我正在使用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 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(image)
谢谢!
答案 0 :(得分:0)
通常,每个像素行在末尾都包含额外的填充像素
bytes 中的完整行大小有多个名称,包括 step , stepWidth 和 stride 。
在struct FlyCaptureImage
中,这称为行增量:iRowInc
。
因此,在您的情况下,您应该指定步幅:
cv::Mat pgImg(FCImg.iRows, FCImg.iCols, CV_8UC3, FCImg.pData, FCImg.iRowInc);