Pointers FlyCaptureImage与OpenCV Mat之间的数据转换
我使用的是PointGrey相机,它返回的图像类型为:Pointers FlyCaptureImage与OpenCV Mat之间的数据转换,pointers,opencv,mat,Pointers,Opencv,Mat,我使用的是PointGrey相机,它返回的图像类型为: typedef struct FlyCaptureImage { // Rows, in pixels, of the image. int iRows; // Columns, in pixels, of the image. int iCols; // Row increment. The number of bytes per row. int iRowInc; // Video mode
typedef struct FlyCaptureImage
{
// Rows, in pixels, of the image.
int iRows;
// Columns, in pixels, of the image.
int iCols;
// Row increment. The number of bytes per row.
int iRowInc;
// Video mode that this image was captured with. This member is only
// populated when the image is returned from a grab call.
FlyCaptureVideoMode videoMode;
// Timestamp of this image.
FlyCaptureTimestamp timeStamp;
// Pointer to the actual image data.
unsigned char* pData;
//
// If the returned image is Y8, Y16, RAW8 or RAW16, this flag indicates
// whether it is a greyscale or stippled (bayer tiled) image. In all
// other modes, this flag has no meaning.
//
bool bStippled;
// The pixel format of this image.
FlyCapturePixelFormat pixelFormat;
// This field is always 1 for single lens cameras. This field is
// used to indicate the number of images contained in the structure
// when dealing with multi-imager systems such as the Bumblebee2
// or XB3? int iNumImages;
int iNumImages;
// Reserved for future use.
unsigned long ulReserved[ 5 ];
} FlyCaptureImage;
然而,我想在OpenCV Mat中处理图像,因此,需要进行转换。我确实成功地尝试迭代图像中的每个元素进行复制。但是速度很慢。因此,最好只复制指针。这是我使用Mat初始化的代码,就像:
MatImg = Mat::Mat(FCImg.iRows, FCImg.iCols, CV_8UC3, FCImg.pData);
请给我一些建议。这是正确的方法吗??我将此转换放在一个独立于主程序的类中,主程序接收返回的Mat图像,例如mycam.getframe(图像)
谢谢 通常,每个像素行的末尾都包含额外的填充像素。以字节为单位的完整行大小有多个名称,包括步长、步长和步幅。
在
struct FlyCaptureImage
中,这称为行增量:iRowInc
因此,在您的情况下,您应该指定步幅,如下所示:
cv::Mat pgImg(FCImg.iRows, FCImg.iCols, CV_8UC3, FCImg.pData, FCImg.iRowInc);
非常感谢。现在可以了。我只对垫子结构了解了一半:(