Ask Your Question
0

Converting from JavaCV

asked 2013-03-05 20:47:17 -0600

andri gravatar image

So, I was using javaCV before. This is the code i use for color tracking

    CvMoments moments = new CvMoments();        
    cvMoments(imgThreshold, moments, 1);

    double momX10 = cvGetSpatialMoment(moments, 1, 0);
    double momY01 = cvGetSpatialMoment(moments, 0, 1);
    double area = cvGetCentralMoment(moments, 0, 0);

When I use OpenCV 2.4.4, I convert the code into this

    Moments moments = new Moments();
    moments(imgThreshold,true);

but its not working.

And what is the replacement of cvGetSpatialMoment?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-03-05 21:11:36 -0600

awknaust gravatar image

According to the documentation, what you should be doing is

Moments m = moments(imgThreshold, true);

In C++ calling new allocates memory for an object and returns a pointer to that object, i.e. the line

m = new Moments();

implies that m's type is "Moments*" not "Moments"

Also to get the moment values, you just get them from the resulting object directly.. m.m00, m.m01 etc.

edit flag offensive delete link more

Comments

I already import org.opencv.core.*, org.opencv.imgproc.Imgproc, org.opencv.imgproc.Moments, but there is no method called "moments" ?

andri gravatar imageandri ( 2013-03-06 02:47:19 -0600 )edit

Question Tools

Stats

Asked: 2013-03-05 20:47:17 -0600

Seen: 1,137 times

Last updated: Mar 05 '13