Is there a way to avoid conversion from YUV to BGR? [closed]

asked 2014-09-17 09:57:37 -0600

carpet gravatar image

updated 2020-10-11 14:28:34 -0600

Hi guys, I am now in the middle of the project, which purpose is to merge frames received from the web (via OPAL Library).

I have written a class Merger, which accepts all of the frames (from different clients). It's possible to get the merged one with the getFrame method.

Frames which i got are in the YUV420p format, but AFAIK, OpenCV's methods support BGR format. So before feeding my function with them I convert: YUV420p -> BGR. Received frame is also converted back, to YUV format.

Can I avoid doing this (and consequently speed up the process? Here is my (pseudo) code:

    unsigned char* receivedFrame()
    {
            // tHeader is raw data with header (it was taken via OPAL library) 
            //...
            //...

            Mat tInputYUV = Mat(tHeader->height * 1.5f, tHeader->width, CV_8UC1, OPAL_VIDEO_FRAME_DATA_PTR(tHeader));
            Mat tInputBGR;
            cvtColor(tInputYUV, tInputBGR, CV_YUV420p2BGR);
            mMerger.addFrame(pID, tInputBGR);
            Mat tMergedFrame = mMerger.getFrame();
            Mat tOutputYUV;
            cvtColor(tMergedFrame, tMergedFrameYUV, CV_BGR2YUV_YV12);

            // do stuff with tOutputYUV -> eg. send it to the client
            //...               
            //...
    }

In getFrame I am using cv::resize and copyTo (from the current frame to the output frame).

Is there a way to speed up this procedure or avoid converting? I tried not doing this, but then after merging my frame is black & white (probably only Y channel remains). Without converting to BGR: image description

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-10-11 14:32:21.338465

Comments

may be it depends upon the stuff you are doing with your image frame. Since most of the opencv function uses BGR as Input you cannot avoid this conversion.

Balaji R gravatar imageBalaji R ( 2014-09-18 01:22:47 -0600 )edit

I use cv::resize and copyTo functions (from cv::Mat class), to scale and copy frames on the merged one. It's like the destination, the canvas.

carpet gravatar imagecarpet ( 2014-09-18 08:24:37 -0600 )edit