Ask Your Question
0

YUV420: text color

asked 2014-03-25 03:23:58 -0500

Kirill gravatar image

Hello!
I use opencv-2.4.8
Before encode YUV420 buffer I have to add some information, e.g. timestamp.
Follow my code:


cv::Mat *_img[3];

_img[0] = new cv::Mat(encop.picHeight, encop.picWidth, CV_8UC1,
            reinterpret_cast<unsigned *="">(_src_mem.virt_uaddr));
_img[1] = new cv::Mat(encop.picHeight / 2, encop.picWidth / 2, CV_8UC1,
            reinterpret_cast<unsigned *="">(_src_mem.virt_uaddr +
                        _size));
_img[2] = new cv::Mat(encop.picHeight / 2, encop.picWidth / 2, CV_8UC1,
        reinterpret_cast<unsigned *="">(_src_mem.virt_uaddr +
                    _size + _size / 4));

CvScalar OCV::yuv_color(float red,
                        float green,
                        float blue)
{
    return cvScalar(0.299 * red + 0.587 * green + 0.114 * blue,
            -0.14713 * red - 0.28886 * green + 0.436 * blue,
            0.615 * red - 0.51499 * green - 0.10001 * blue);
}

const CvScalar color = OCV::yuv_color(6.0, 249.0, 223.0);

putText(*_img[0], _osd, cv::Point(20, 20), cv::FONT_HERSHEY_SIMPLEX,
                0.5, color, 0, 16);
putText(*_img[1], _osd, cv::Point(10, 10), cv::FONT_HERSHEY_SIMPLEX,
                0.25, color, 0, 16);
putText(*_img[2], _osd, cv::Point(10, 10), cv::FONT_HERSHEY_SIMPLEX,
                0.25, color, 0, 16);
 

Code work fine, but I have little proble:
1. I get green text if I use RGB color
2. I get magenta text if I use YUV color

How can control text color for YUV420?
Thank you and excuse my bad english.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-03-25 05:37:18 -0500

There are several things you need to think about before going ahead with color channels:

  1. OpenCV uses BGR color channels and not RGB color channels! This is an important difference when switching between color channels.
  2. You are using the scalar color to define the values of your text. However you are assuming that it is RGB color space, but it is actually the BGR color space.
  3. Also it is normal that YUV color space, can result in different colors then BGR depending on the values. B value =/= Y value, G value =/= U value, ... Keep this in mind!
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2014-03-25 03:23:58 -0500

Seen: 637 times

Last updated: Mar 25 '14