- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If I'm using the following code:
if (img_color->AcquireAccess(PXCImage::ACCESS_READ, &temp_data) == PXC_STATUS_NO_ERROR) { memcpy(mat_color.data, temp_data.planes[0], sizeof(unsigned char) * 3 * depth_width * depth_height); img_color->ReleaseAccess(&temp_data); } }
The memcpy function will sometimes break, with unable to read exception.
The fix is to always specify the required pixel format, like
img_color->AcquireAccess(PXCImage::ACCESS_READ, PXCImage::PIXEL_FORMAT_RGB24, &temp_data)
I guess it means there is a bug both with the function and the status returning.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Zsolt, I can propose a possible reason for this issue, though it's a bit complicated.
In its native data format, the image from the camera is stored in YUY2 format, which is a type of YUV format, and the data is stored in 3 different "planes" or data buffers (This is why the sdk gives you access to temp_data.planes[0..3]). The Y plane (temp_data.plane[0]) contains only a third of the color information, basically a grayscale version of the image, and the U and V planes (temp_data.plane[1] and temp_data.plane[2]) contain the data needed to recreate the color info, and they are both downsampled to half of the original image size. If you attempt to use memcpy and read from the plane[0] buffer only, then you'll run past the real data and into unallocated memory.
Because a good amount of developers aren't familiar with the YUY2 standard and how to convert back to RGB pixels, the SDK includes the ability to specify the desired output format, usually RGB 24 or RGBA 32, and the computation is handled on the backend before the planes[0] data is populated.
This is why your second code snippet works while your first throws an exception.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In fact, you can include a check for the data format before you perform your copy, to be on the safe side. If you are expecting RGB24 data, then you should confirm after acquiring access that temp_data.format matches PIXEL_FORMAT_RGB24. Anything else will give you corrupted data at best and throw an exception at worst.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page