I haven't developed for Tango for quite a while, but recently I updated to the latest version of Tango Java API and I noticed that TangoImageBuffer
objects now have format == 17
, which is:
public static final int YCRCB_420_SP = 17;
As far as I remember, in previous versions it used to be YV12
rather than YCRCB_420_SP
.
public static final int YV12 = 842094169;
I used to apply OpenCV cvtColor
function to convert it to BGR:
cv::Mat imageBgr(720, 1080, CV_8UC3);
cv::Mat image(3 * 720 / 2, 1280, CV_8UC1);
cv::cvtColor(image, imageBgr, cv::COLOR_YUV2RGB_NV12);
Is there a way to read YCRCB_420_SP
using OpenCV? I tried COLOR_YCrCb2BGR
and similar modes, but they don't work.
Apparently, COLOR_YUV2RGB_NV12
still works and produces somewhat reasonable result:
But it feels like colors are off and everything looks very yellow-ish. Or am I being paranoid?
My question is, what is the right way to read YCRCB_420_SP
images? Is it correct to apply OpenCV cv::COLOR_YUV2RGB_NV12
?
EDIT:
I tried using NV21 as @fireant suggested, but this one clearly does not work:
NV12 was much closer to the original colors. The code is:
cv::cvtColor(image, imageBgr, cv::COLOR_YUV2RGB_NV21);
The image format should be YUV NV21 not NV12. OpenCV can convert an image from that format to BGR or RGB.
Just a guess, it seems you're using RGB instead of BGR, the image after NV21 with BGR looks like this: