Drawing rectangle on NV12 frame without conversion

asked 2020-07-05 10:20:01 -0500

shiva gravatar image

Hi All,

I want to draw rectangle on a NV12 frame. One way I see is converting it to BGR using cvtColor with color code as CV_YUV2BGR_NV12. and then apply rectangle.

But the issue with this approach is that, I can't convert it back to NV12 as there is no color conversion code for it.

Other approach I can think of is, drawing rectangle on NV12 frame itself by diving the frame into Y mat plane and UV mat plane. (like below)

Mat luma (height, width, CV_8UC1, buff);
char *chroma_buf = buff + (height * width);
Mat chroma (height/2, width/2, CV_16UC1, chroma_buf);

strong text

If I have to draw a red color rectangle. What value of the sclar value we have to pass to both luma and chroma mat.

For example:

   rectangle (luma, Point (200, 200), Point (400, 400), Scalar (x), 1, 1, 0);
   rectangle (chroma, Point (200/2, 200/2), Point (400/2, 400/2), Scalar (y), 1, 1, 0);

Now what should be the value of x and y here to get red rectangle.

Please suggest if there is an alternative way to do this.

edit retag flag offensive close merge delete