1

If I understand correctly, when I use OpenCV to convert YUV to RGB using the cvtColor(CV_YUV420sp2BGR) function I actually call YUV420sp2RGB888Invoker class.

The conversion formula is

R = 1.164(Y - 16) + 1.596(V - 128)
G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128)
B = 1.164(Y - 16) + 2.018(U - 128)

These coefficients apply to CCIR 601 spec where the ranges of Y, U and V are respectively [16 … 235], [16 … 240] and [16 … 240].

But the Android camera (specifically, on Snapdragon) seems to return the NV21 image in full (JFIF) range of [0 … 255] for all components (See also https://stackoverflow.com/a/12702836/192373).

Is there a way to use OpenCV color conversion for the JFIF color range?

Community
  • 1
  • 1
Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • 1
    There's a lot of [similar posts](https://stackoverflow.com/search?q=%5Bopencv%5D+%5Bandroid%5D+yuv). Have you tried them? – karlphillip Oct 19 '14 at 21:31
  • Thanks for the link, @[karlphillip](http://stackoverflow.com/users/176769/karlphillip). I definitely read most of these entire, and even had answered some of them. I even link to one of them. But I have not found one that concerns my specific question. – Alex Cohn Oct 20 '14 at 02:56

1 Answers1

0

According to this OpenCV documentation: http://docs.opencv.org/modules/imgproc/doc/miscellaneous_transformations.html

The transform CV_YCrCb2BGR seems to be what you're looking for. It uses the same coefficients that are mentioned in the stackoverflow answer you linked (full range with 1.403, 0.714, 0.344 and 1.773).

Jan Rüegg
  • 9,587
  • 8
  • 63
  • 105
  • Thanks, but if I am not missing something, this transform assumes 420 planar, not NV21 semi-planar format. – Alex Cohn Apr 17 '15 at 14:19
  • @Alex Cohn hi, have you by any chance, managed to figure it out? Android's camera image preview output holds 3 planes,which the Y is not twice the resolution of U and V in both dimensions, therefore I couldn't use the approach here: https://stackoverflow.com/questions/50230188/yuv420-to-bgr-image-from-pixel-pointers – JammingThebBits Jun 17 '21 at 13:20
  • @JammingThebBits You are welcome to look at https://github.com/flutter/flutter/issues/26348#issuecomment-675728428 – Alex Cohn Jun 17 '21 at 14:46
  • Thank you @AlexCohn , I appreciate it!! – JammingThebBits Jun 17 '21 at 16:46