Ask Your Question

A way to replace cvGet2D( distribution, y, x )

asked 2013-07-23 14:56:33 -0500

updated 2013-07-23 15:07:05 -0500

I have the following function in a piece of code that I am completely converting to the C++ interface.

cvGet2D( distribution, y, x )

This piece of code has as return element a CvScalar. However, I want the output to be a Scalar type. Is there any way to do this decently? Using any other C++ function?

I tried something like this:<float>(x,y);

But I am guessing this will return a single element and wont fit into a Scalar?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-07-23 16:03:07 -0500

Notas gravatar image

updated 2013-07-23 16:04:00 -0500

Scalar is a 4 element Scalar_<double> vector in OpenCV. Scalar_ has a constructor where you can pass a value of the Scalar_ type, in the case of Scalar it would be double.

So to make your own cvGet2D, you can create your Scalar like this:

Scalar scal(<float>(x,y));

(btw. Mat::at is row first, column last. Just fyi because .at<float>(x,y) had me confused and is an error that's easily overlooked)

edit flag offensive delete link more

Question Tools


Asked: 2013-07-23 14:56:33 -0500

Seen: 1,121 times

Last updated: Jul 23 '13