Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Is there a way to avoid conversion from YUV to BGR?

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

Is there a way to avoid conversion from YUV to BGR?

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