0
votes

I know Mat data save each pixel data(RGB data in a column) as a unsigned char. And texture data in unity3d is byte[]. I try to do the following thing, but the result is not right, the image capture from the camera displayed in the hwind is not right.

Mat src_frame;//this is every frame that captured from the current camera
D3DLOCKED_RECT d3d_rect;
byte *pSrc = src_frame.data;
byte *pDest = (byte *)d3d_rect.pBits;

int stride = d3d_rect.Pitch;
int pixel_w_size = src_frame.cols;
for (unsigned long i = 0; i < src_frame.rows; i++){
    memcpy(pDest, pSrc, pixel_w_size);
    pDest += stride;
    pSrc += pixel_w_size;
}

Only gray image shows, I don't know why this happens. Does the Mat data sequence is different from the texture data? Their data both contain the RGB information.

1

1 Answers

0
votes

pixel_w_size should be src_frame.cols multiplied with the bytes per pixel (3 in case of RGB) or even better use elemSize().

So use:

int pixel_w_size = src_frame.cols * src_frame.elemSize();