Ask Your Question
1

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

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

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

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:

distribution.at<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
2

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

Notas gravatar image

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

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(distribution.at<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

Stats

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

Seen: 1,443 times

Last updated: Jul 23 '13