Ask Your Question

Can I use cv::cuda::add for per-element addition to Mat?

asked 2019-05-16 08:21:14 -0500

hua gravatar image

I want to add 1 to all of the pixels in the Mat. In usual OpenCV code result = cv::Mat + 1;. And I want to write that in OpenCV CUDA like the following.

cv::cuda::add(cuda_Mat1, 1, cuda_ResultMat);

Can I use like this?

Thank you for your time.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2019-05-16 08:37:06 -0500

HYPEREGO gravatar image

updated 2019-05-16 08:37:34 -0500

You can try by your own, it need less time to test it than write a question here :D. The documentation say yes, you can do in this way since the second parameter can be a scalar or a matrix. If it doesn't work, try cv::Scalar(1);

edit flag offensive delete link more


cv::cuda::add in this documentation it says Computes a matrix-matrix or matrix-scalar sum. I'm confused I have to use just 1 or as you said. Anyway, thanks.

hua gravatar imagehua ( 2019-05-16 08:47:25 -0500 )edit

matrix-matrix means that src1 and src2 are both matrix, with same size, in that case the resulting matrix contain the element-per-element sum i.e. dst(i,j) = src1(i,j)+src2(i,j) while if you pass to the function a scalar, let's say X as you would like to do, the resulting matrix will be dst(i,j) = src1(i,j) + X

If you found my answer useful please accept it as valid answer :)

HYPEREGO gravatar imageHYPEREGO ( 2019-05-16 09:55:40 -0500 )edit

Thank you, I am understanding now:)

hua gravatar imagehua ( 2019-05-16 10:01:07 -0500 )edit

@HYPEREGO Could you answer another question of mine? I'm asking about cv::cuda::createGaussianFilter.

hua gravatar imagehua ( 2019-05-16 10:03:10 -0500 )edit

Question Tools

1 follower


Asked: 2019-05-16 08:21:14 -0500

Seen: 293 times

Last updated: May 16 '19