Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
Bridges over other frameworks

Namespaces

namespace  visp::cnpy

Classes

class  vpConvert

Functions

template<typename MaskType>
static std::enable_if< std::is_same< MaskType, unsignedchar >::value||std::is_same< MaskType, bool >::value, int >::type vpImageConvert::depthToPointCloud (const vpImage< uint16_t > &depth_raw, float depth_scale, const vpCameraParameters &cam_depth, pcl::PointCloud< pcl::PointXYZ >::Ptr pointcloud, std::mutex *pointcloud_mutex=nullptr, const vpImage< MaskType > *depth_mask=nullptr, float Z_min=0.2, float Z_max=2.5)
template<typename MaskType>
static std::enable_if< std::is_same< MaskType, unsignedchar >::value||std::is_same< MaskType, bool >::value, int >::type vpImageConvert::depthToPointCloud (const vpImage< vpRGBa > &color, const vpImage< uint16_t > &depth_raw, float depth_scale, const vpCameraParameters &cam_depth, pcl::PointCloud< pcl::PointXYZRGB >::Ptr pointcloud, std::mutex *pointcloud_mutex=nullptr, const vpImage< MaskType > *depth_mask=nullptr, float Z_min=0.2, float Z_max=2.5)
static void vpImageConvert::convert (const cv::Mat &src, vpImage< vpRGBa > &dest, bool flip=false)
static void vpImageConvert::convert (const cv::Mat &src, vpImage< unsigned char > &dest, bool flip=false, unsigned int nThreads=0)
static void vpImageConvert::convert (const cv::Mat &src, vpImage< float > &dest, bool flip=false)
static void vpImageConvert::convert (const cv::Mat &src, vpImage< double > &dest, bool flip=false)
static void vpImageConvert::convert (const cv::Mat &src, vpImage< uint16_t > &dest, bool flip=false)
static void vpImageConvert::convert (const cv::Mat &src, vpImage< vpRGBf > &dest, bool flip=false)
static void vpImageConvert::convert (const vpImage< vpRGBa > &src, cv::Mat &dest)
static void vpImageConvert::convert (const vpImage< unsigned char > &src, cv::Mat &dest, bool copyData=true)
static void vpImageConvert::convert (const vpImage< float > &src, cv::Mat &dest, bool copyData=true)
static void vpImageConvert::convert (const vpImage< double > &src, cv::Mat &dest, bool copyData=true)
static void vpImageConvert::convert (const vpImage< vpRGBf > &src, cv::Mat &dest)

Detailed Description

Conversion from/to OpenCV, NPY/NPZ, PCL ...

Function Documentation

◆ convert() [1/11]

void vpImageConvert::convert ( const cv::Mat & src,
vpImage< double > & dest,
bool flip = false )
static

Converts cv::Mat CV_32FC1 format to ViSP vpImage<double>.

Parameters
[in]src: OpenCV image in CV_32FC1 format.
[out]dest: ViSP image in double format.
[in]flip: When true during conversion flip image vertically.

Definition at line 339 of file vpImageConvert_opencv.cpp.

References convert().

◆ convert() [2/11]

void vpImageConvert::convert ( const cv::Mat & src,
vpImage< float > & dest,
bool flip = false )
static

Converts cv::Mat CV_32FC1 / CV_16SC1 format to ViSP vpImage<float>.

Parameters
[in]src: OpenCV image in CV_32FC1 / CV_16SC1 format.
[out]dest: ViSP image in float format.
[in]flip: When true during conversion flip image vertically.

Definition at line 296 of file vpImageConvert_opencv.cpp.

References vpException::badValue.

◆ convert() [3/11]

void vpImageConvert::convert ( const cv::Mat & src,
vpImage< uint16_t > & dest,
bool flip = false )
static

Converts cv::Mat CV_16UC1 format to ViSP vpImage<uint16_t>.

Parameters
[in]src: OpenCV image in CV_16UC1 format.
[out]dest: ViSP image in uint16_t format.
[in]flip: When true during conversion flip image vertically.

Definition at line 361 of file vpImageConvert_opencv.cpp.

References vpException::fatalError.

◆ convert() [4/11]

void vpImageConvert::convert ( const cv::Mat & src,
vpImage< unsigned char > & dest,
bool flip = false,
unsigned int nThreads = 0 )
static

Convert a cv::Mat to a vpImage<unsigned char>.

A cv::Mat is an OpenCV image class.

Warning
This function is only available if OpenCV was detected during the configuration step.
Parameters
[in]src: Source image in OpenCV format.
[out]dest: Destination image in ViSP format.
[in]flip: Set to true to vertically flip the converted image.
[in]nThreads: number of threads to use if OpenMP is available. If 0 is passed, OpenMP will choose the number of threads.
#include <visp3/core/vpImage.h>
#include <visp3/core/vpImageConvert.h>
#include <visp3/io/vpImageIo.h>
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
int main()
{
#if defined(VISP_HAVE_OPENCV)
vpImage<unsigned char> Ig; // A grayscale image
cv::Mat Ip;
// Read an image on a disk with openCV library
Ip = cv::imread("image.pgm", cv::IMREAD_GRAYSCALE); // Second parameter for a gray level.
// Convert the grayscale cv::Mat into vpImage<unsigned char>
// ...
#endif
}
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
Definition of the vpImage class member functions.
Definition vpImage.h:131

Definition at line 216 of file vpImageConvert_opencv.cpp.

References BGRaToGrey(), and BGRToGrey().

◆ convert() [5/11]

BEGIN_VISP_NAMESPACE void vpImageConvert::convert ( const cv::Mat & src,
vpImage< vpRGBa > & dest,
bool flip = false )
static

Convert a cv::Mat to a vpImage<vpRGBa>.

A cv::Mat is an OpenCV image class.

If the input image is of type CV_8UC1 or CV_8UC3, the alpha channel is set to vpRGBa::alpha_default, or 0 in certain case (see the warning below).

Warning
This function is only available if OpenCV (version 2.1.0 or greater) was detected during the configuration step.
If ViSP is built with SSSE3 flag and the CPU supports this intrinsics set, alpha channel will be set to 0, otherwise it will be set to vpRGBa::alpha_default (255).
Parameters
[in]src: Source image in OpenCV format.
[out]dest: Destination image in ViSP format.
[in]flip: Set to true to vertically flip the converted image.
#include <visp3/core/vpImage.h>
#include <visp3/core/vpImageConvert.h>
#include <visp3/core/vpRGBa.h>
#include <visp3/io/vpImageIo.h>
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
int main()
{
#if defined(VISP_HAVE_OPENCV)
vpImage<vpRGBa> Ic; // A color image
cv::Mat Ip;
// Read an image on a disk with openCV library
Ip = cv::imread("image.pgm", cv::IMREAD_COLOR); // Second parameter for a BGR encoding.
// Convert the grayscale cv::Mat into vpImage<vpRGBa>
// ...
#endif
}

Definition at line 94 of file vpImageConvert_opencv.cpp.

References vpRGBa::A, vpRGBa::alpha_default, vpRGBa::B, vpRGBa::G, and vpRGBa::R.

◆ convert() [6/11]

void vpImageConvert::convert ( const cv::Mat & src,
vpImage< vpRGBf > & dest,
bool flip = false )
static

Converts cv::Mat CV_32FC3 format to ViSP vpImage<vpRGBf>.

Parameters
[in]src: OpenCV image in CV_32FC3 format.
[out]dest: ViSP image in vpRGBf format.
[in]flip: When true during conversion flip image vertically.

Definition at line 397 of file vpImageConvert_opencv.cpp.

References vpRGBf::B, vpException::badValue, vpRGBf::G, and vpRGBf::R.

◆ convert() [7/11]

void vpImageConvert::convert ( const vpImage< double > & src,
cv::Mat & dest,
bool copyData = true )
static

Convert a float-64 ViSP image into a cv::Mat(CV_32FC1).

Parameters
[in]srcA float-64 ViSP image.
[in]destA cv::Mat(CV_32FC1).
[in]copyDataIf true, the image is copied and modification in one object will not modified the other.

Definition at line 558 of file vpImageConvert_opencv.cpp.

References convert(), vpImage< Type >::getCols(), and vpImage< Type >::getRows().

◆ convert() [8/11]

void vpImageConvert::convert ( const vpImage< float > & src,
cv::Mat & dest,
bool copyData = true )
static

Convert a float-32 ViSP image into a cv::Mat(CV_32FC1).

Parameters
[in]srcA float-32 ViSP image.
[in]destA cv::Mat(CV_32FC1).
[in]copyDataIf true, the image is copied and modification in one object will not modified the other.

Definition at line 538 of file vpImageConvert_opencv.cpp.

References vpImage< Type >::bitmap, vpImage< Type >::getCols(), and vpImage< Type >::getRows().

◆ convert() [9/11]

void vpImageConvert::convert ( const vpImage< unsigned char > & src,
cv::Mat & dest,
bool copyData = true )
static

Convert a vpImage<unsigned char> to a cv::Mat grey level image.

A cv::Mat is an OpenCV image class. See http://opencv.willowgarage.com for the general OpenCV documentation, or http://opencv.willowgarage.com/documentation/cpp/core_basic_structures.html for the specific Mat structure documentation.

Warning
This function is only available if OpenCV version 2.1.0 or greater was detected during the configuration step.
Parameters
[in]src: Source image.
[out]dest: Destination image.
[in]copyData: If true, the image is copied and modification in one object will not modified the other.
#include <visp3/core/vpImageConvert.h>
#include <visp3/io/vpImageIo.h>
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
int main()
{
#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_IMGCODECS)
vpImage<unsigned char> Ig; // A grayscale image
cv::Mat Ip;
// Read an image on a disk
vpImageIo::read(Ig, "image.pgm");
// Convert the vpImage<unsigned char> in to grayscale cv::Mat
// Treatments on cv::Mat Ip
//...
// Save the cv::Mat on the disk
cv::imwrite("image-cv.pgm", Ip);
#endif
}
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)

Definition at line 518 of file vpImageConvert_opencv.cpp.

References vpImage< Type >::bitmap, vpImage< Type >::getCols(), and vpImage< Type >::getRows().

◆ convert() [10/11]

void vpImageConvert::convert ( const vpImage< vpRGBa > & src,
cv::Mat & dest )
static

Convert a vpImage<vpRGBa> to a cv::Mat color image.

A cv::Mat is an OpenCV image class. See http://opencv.willowgarage.com for the general OpenCV documentation, or http://opencv.willowgarage.com/documentation/cpp/core_basic_structures.html for the specific Mat structure documentation.

Warning
This function is only available if OpenCV version 2.1.0 or greater was detected during the configuration step.
Parameters
[in]src: Source image (vpRGBa format).
[out]dest: Destination image (BGR format).
#include <visp3/core/vpImageConvert.h>
#include <visp3/io/vpImageIo.h>
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
int main()
{
#if defined(VISP_HAVE_OPENCV)
vpImage<vpRGBa> I; // A color image
cv::Mat Icv;
// Read an image on a disk
vpImageIo::read(I, "image.ppm");
// Convert the image into color cv::Mat.
// Treatments on cv::Mat Icv
//...
// Save the cv::Mat on the disk
cv::imwrite("image-cv.ppm", Icv);
#endif
}

Definition at line 468 of file vpImageConvert_opencv.cpp.

References vpImage< Type >::bitmap, vpImage< Type >::getCols(), and vpImage< Type >::getRows().

◆ convert() [11/11]

void vpImageConvert::convert ( const vpImage< vpRGBf > & src,
cv::Mat & dest )
static

Convert a vpRGBf ViSP image into a cv::Mat(CV_32FC3) that uses BGR format.

Parameters
[in]srcA vpRGBf ViSP image.
[in]destA cv::Mat(CV_32FC3) that uses BGR format.

Definition at line 578 of file vpImageConvert_opencv.cpp.

References vpImage< Type >::bitmap, vpImage< Type >::getCols(), and vpImage< Type >::getRows().

◆ depthToPointCloud() [1/2]

template<typename MaskType>
std::enable_if< std::is_same< MaskType, unsignedchar >::value||std::is_same< MaskType, bool >::value, int >::type vpImageConvert::depthToPointCloud ( const vpImage< uint16_t > & depth_raw,
float depth_scale,
const vpCameraParameters & cam_depth,
pcl::PointCloud< pcl::PointXYZ >::Ptr pointcloud,
std::mutex * pointcloud_mutex = nullptr,
const vpImage< MaskType > * depth_mask = nullptr,
float Z_min = 0.2,
float Z_max = 2.5 )
inlinestatic

Convert a raw depth image into a pcl::PointCloud that has no texture.

Parameters
[in]depth_rawRaw depth image.
[in]depth_scaleDepth scale to convert the raw depth image into meters.
[in]cam_depthThe depth camera parameters.
[out]pointcloudA pointer towards the pcl::PointCloud that has no texture.
[in]pointcloud_mutexOptional, if set a pointer towards the mutex that protects the point cloud.
[in]depth_maskOptional, if set a pointer towards a binary image that indicates if the point must be considered or not. (Either true or a value different from 0 to keep the point, false or 0 to discard it).
[in]Z_minThe minimum depth to keep the point.
[in]Z_maxThe maximum depth to keep the point.
See also
To see how to use it in the context of color segmentation on a point-cloud , Tutorial: Point cloud segmentation using HSV color scale
Examples
tutorial-hsv-segmentation-pcl-viewer.cpp, and tutorial-hsv-segmentation-pcl.cpp.

Definition at line 216 of file vpImageConvert.h.

References vpImage< Type >::bitmap, vpPixelMeterConversion::convertPoint(), vpImage< Type >::getHeight(), vpImage< Type >::getSize(), vpImage< Type >::getWidth(), and vpImageException::notInitializedError.

◆ depthToPointCloud() [2/2]

template<typename MaskType>
std::enable_if< std::is_same< MaskType, unsignedchar >::value||std::is_same< MaskType, bool >::value, int >::type vpImageConvert::depthToPointCloud ( const vpImage< vpRGBa > & color,
const vpImage< uint16_t > & depth_raw,
float depth_scale,
const vpCameraParameters & cam_depth,
pcl::PointCloud< pcl::PointXYZRGB >::Ptr pointcloud,
std::mutex * pointcloud_mutex = nullptr,
const vpImage< MaskType > * depth_mask = nullptr,
float Z_min = 0.2,
float Z_max = 2.5 )
inlinestatic

Convert a raw depth image in a textured pcl::PointCloud using a vpImage<RGBa> that is aligned with the raw depth image to get the texture.

Parameters
[in]colorThe color image that gives the texture of the points.
[in]depth_rawRaw depth image.
[in]depth_scaleDepth scale to convert the raw depth image into meters.
[in]cam_depthThe depth camera parameters.
[out]pointcloudA pointer towards the pcl::PointCloud that has no texture.
[in]pointcloud_mutexOptional, if set a pointer towards the mutex that protects the point cloud.
[in]depth_maskOptional, if set a pointer towards a binary image that indicates if the point must be considered or not. (Either true or a value different from 0 to keep the point, false or 0 to discard it).
[in]Z_minThe minimum depth to keep the point.
[in]Z_maxThe maximum depth to keep the point.
See also
To see how to use it in the context of color segmentation on a point-cloud , Tutorial: Point cloud segmentation using HSV color scale

Definition at line 330 of file vpImageConvert.h.

References vpImage< Type >::bitmap, vpPixelMeterConversion::convertPoint(), vpImage< Type >::getHeight(), vpImage< Type >::getSize(), vpImage< Type >::getWidth(), and vpImageException::notInitializedError.