2

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:

YCRCB_420_SP read as NV12

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:

NV21

NV12 was much closer to the original colors. The code is:

cv::cvtColor(image, imageBgr, cv::COLOR_YUV2RGB_NV21);
Aleksei Petrenko
  • 6,698
  • 10
  • 53
  • 87
  • 1
    I'm stuck on a similar problem... I'm working with the Tango **Unity** SDK, and our callback to get camera data (TangoUnityImageData) still says it gives us YV12 frames. I am on the caporales release. But these frames are not working as expected... perhaps it has changed like you show, and is mis-labeled in TangoUnity SDK.. https://developers.google.com/tango/apis/unity/reference/class/tango/tango-enums#class_tango_1_1_tango_enums_1ae177f114ecf6fd14e2f6152005ecfe0eaf4f398ec3ced7faeea573a7546fc3036 – Jethro Feb 03 '17 at 08:49

1 Answers1

2

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: enter image description here

fireant
  • 14,080
  • 4
  • 39
  • 48