Ask Your Question
0

stitching 2 images together in CUDA like hconcat?

asked 2014-11-03 11:31:46 -0600

Echo88 gravatar image

updated 2020-10-01 09:04:09 -0600

berak gravatar image

Is there a function or workaround-method to horizontally concatenate 2 images together directly in CUDA? My program grabs 2 frames by highspeed-cameras, uploads them to CUDA, processes them and downloads them, then the images are concatenated by hconcat on the cpu (which i need to avoid as it drastically reduces my framerate) and displayed via OpenGL.

Surely its possible to stitch the images together via OpenGL, but i would rather like to do it via CUDA. I use OpenCV 3.0 and CUDA 6.5.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2020-10-01 07:40:18 -0600

agrau gravatar image

updated 2020-10-01 09:05:48 -0600

berak gravatar image

I made this hconcat function, I hope it helps.

void custom_hconcat(const cv::cuda::GpuMat src1, const cv::cuda::GpuMat src2, cv::cuda::GpuMat& result) {

    int size_cols = src1.cols + src2.cols;
    int size_rows = std::max(src1.rows, src2.rows);
    cv::cuda::GpuMat hconcat(size_rows, size_cols, src1.type());
    src2.copyTo(hconcat(cv::Rect(0, 0, src2.cols, src2.rows)));
    src1.copyTo(hconcat(cv::Rect(src2.cols, 0, src1.cols, src1.rows)));

    result = hconcat.clone();
}
edit flag offensive delete link more
0

answered 2015-02-02 11:53:02 -0600

dtmoodie gravatar image

updated 2020-10-01 09:04:40 -0600

berak gravatar image

You can allocate a matrix of the correct size and then copy the images into the new matrix manually with the following:

cv::cuda::GpuMat NewImg(img1.rows, img1.cols + img2.cols, img1.type);
img1.copyTo(NewImg(cv::Rect(0,0,img1.cols,img1.rows)));
img2.copyTo(NewImg(cv::Rect(img1.cols,img1.rows, img2.cols,img2.rows)));
edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-11-03 11:31:46 -0600

Seen: 2,670 times

Last updated: Oct 01 '20