The reason for your log output is that your pixel values are of type uint8_t
, which will be interpreted as unsigned char
(on iOS, at least) when you try to output it to the console. So the log output is the character represented by that pixel value. To output the corresponding numerical value, cast the value to an int
, like so:
std::cout << "Y: " << (int)yuvPixel.val[0] << std::endl;
std::cout << "U: " << (int)yuvPixel.val[1] << std::endl;
std::cout << "V: " << (int)yuvPixel.val[2] << std::endl;
Also, your posted code was outputting the same element three times, and bgrPixel
was undefined. I have corrected those errors in this snippet as well.
If you are only interested in the luminance information, you could instead call
cv::cvtColor(image, frame_yuv, CV_BGR2GRAY);
Which does the same color conversion as the Y channel of YUV, but will be more efficient.