Attention! This forum will be made read-only by Dec-20. Please migrate to Most of existing active users should've received invitation by e-mail.
Ask Your Question

stitching 2 images together in CUDA like hconcat?

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

Echo88 gravatar image

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

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

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

agrau gravatar image

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

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

answered 2015-02-02 11:53:02 -0500

dtmoodie gravatar image

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

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);
img2.copyTo(NewImg(cv::Rect(img1.cols,img1.rows, img2.cols,img2.rows)));
edit flag offensive delete link more
Login/Signup to Answer

Question Tools


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

Seen: 1,172 times

Last updated: Oct 01