Is there a way to avoid conversion from YUV to BGR? [closed]
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:
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.
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.