Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version
  • Read Y, U and V binary files into byte buffers
    • Create OpenCV Mat object from the created buffers.
    • Resize U and V Mats to the size of Y.
    • Merge Y and resized U and V.
    • Convert from YUV to BGR

Size actual_size(1280, 720);
Size half_size(1280/2, 720/2); //Size half_size(1280/2, 720/2);
Mat ndk_rgb_img, ndk_rgb_img_out;
int ndk_image_width = 1280; 
int ndk_image_height = 720;
uint8_t *yPixel, *uPixel, *vPixel;
int32_t yLen, uLen, vLen;
int32_t uvPixelStride;
int32_t uvRowStride;



AImage_getPlaneData(image, 0, &yPixel, &yLen); //Y
AImage_getPlaneData(image, 1, &uPixel, &uLen); // U
AImage_getPlaneData(image, 2, &vPixel, &vLen); //V
AImage_getPlanePixelStride(image, 1, &uvPixelStride); // foulée en pixel
AImage_getPlaneRowStride (image, 1, &uvRowStride); // foulée en ligne

// cout << "length Y " <<  yLen << endl;
// cout << "length U " << uLen << endl;
// cout << "length V " <<  vLen << endl;
//cout << "uvPixelStride " <<  uvPixelStride << endl;
//cout << "uvRowStride " <<  uvRowStride << endl;

Mat y(actual_size, CV_8UC1, yPixel);
Mat u(half_size, CV_8UC2, uPixel); 
Mat v(half_size, CV_8UC2, vPixel); 
long addr_diff = u.data - v.data;
if (addr_diff > 0) { 
    assert(addr_diff == 1); 
    cvtColorTwoPlane(y, u, ndk_rgb_img, COLOR_YUV2BGR_NV12); //COLOR_YUV2RGB_NV12
} else { 
    assert(addr_diff == -1); 
    cvtColorTwoPlane(y, v, ndk_rgb_img, COLOR_YUV2BGR_NV21); 
}

Work for me very well