Ask Your Question
0

How to combine Color conversion(BGRA->BGR) and Remap operations?

asked 2020-01-01 15:27:55 -0600

JeyP4 gravatar image

updated 2020-01-02 10:32:52 -0600

I want to convert a distorted BGRx image to undistorted BGR in one operation to prevent multiple data copying.

So

cv::Mat BGRx(720, 1280, CV_8UC4);  // (INPUT) comes from Gstreamer's vaapipostproc
cv::Mat map1, map2;                // 720x1600, calculated from Camera & Distortion matrix
cv::Mat BGR(720, 1600, CV_8UC3);   // (OUTPUT)

// 2-Step process
cv::Mat temp;
cv::cvtColor(BGRx, temp, CV_BGRA2BGR);
cv::remap(temp, BGR, map1, map2, cv::INTER_LINEAR);

Why I want to perform in single operation? Since both process are data copying process. I want to eliminate avoidable data copying.

Why I want BGR output instead of BGRA? Because further image processing of output image will be less computationally expensive due to only 3-layers instead of 4.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-01-02 03:43:12 -0600

mvuori gravatar image

I guess you need to get the source code for remap and make a custom version of it. But the performance benefit would likely be very small, as remap is quite computationally heavy compared to the trivial Mat type conversion - not a simple data copying process.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-01-01 15:27:55 -0600

Seen: 4,106 times

Last updated: Jan 02 '20