Ask Your Question
0

Error in Hu-moments calculation

asked 2014-09-05 00:44:37 -0600

jamesnzt gravatar image

updated 2014-09-05 01:49:19 -0600

berak gravatar image
    cvtColor(forcalc,forcalc,CV_BGR2GRAY);
    threshold(forcalc,forcalc,1, 255,cv::THRESH_BINARY_INV);
    double hu[7];
    int eros = 10;
    Mat ele = getStructuringElement( MORPH_ELLIPSE, Size( 2*eros+ 1, 2*eros+1 ), Point( eros, eros) );
    erode(forcalc,forcalc,ele );

     Moments moments(forcalc, false); 
     HuMoments(&moments,  hu[7]);

In the above code i get the following errors

opcorect2.cpp: In function ‘int main(int, char**)’:
opcorect2.cpp:238:31: error: no matching function for call to ‘cv::Moments::Moments(cv::Mat&, bool)’
opcorect2.cpp:238:31: note: candidates are:
In file included from opcorect2.cpp:1:0:
/usr/local/include/opencv2/imgproc/imgproc.hpp:1103:5: note: cv::Moments::Moments(const CvMoments&)
/usr/local/include/opencv2/imgproc/imgproc.hpp:1103:5: note:   candidate expects 1 argument, 2 provided
/usr/local/include/opencv2/imgproc/imgproc.hpp:1100:5: note: cv::Moments::Moments(double, double, double, double, double, double, double, double, double, double)
/usr/local/include/opencv2/imgproc/imgproc.hpp:1100:5: note:   candidate expects 10 arguments, 2 provided
/usr/local/include/opencv2/imgproc/imgproc.hpp:1098:5: note: cv::Moments::Moments()
/usr/local/include/opencv2/imgproc/imgproc.hpp:1098:5: note:   candidate expects 0 arguments, 2 provided
/usr/local/include/opencv2/imgproc/imgproc.hpp:1094:24: note: cv::Moments::Moments(const cv::Moments&)
/usr/local/include/opencv2/imgproc/imgproc.hpp:1094:24: note:   candidate expects 1 argument, 2 provided
opcorect2.cpp:239:27: error: no matching function for call to ‘HuMoments(cv::Moments*, double&)’
opcorect2.cpp:239:27: note: candidates are:
In file included from opcorect2.cpp:1:0:
/usr/local/include/opencv2/imgproc/imgproc.hpp:1119:17: note: void cv::HuMoments(const cv::Moments&, double*)
/usr/local/include/opencv2/imgproc/imgproc.hpp:1119:17: note:   no known conversion for argument 1 from ‘cv::Moments*’ to ‘const cv::Moments&’
/usr/local/include/opencv2/imgproc/imgproc.hpp:1120:19: note: void cv::HuMoments(const cv::Moments&, cv::OutputArray)
/usr/local/include/opencv2/imgproc/imgproc.hpp:1120:19: note:   no known conversion for argument 1 from ‘cv::Moments*’ to ‘const cv::Moments&’

The image(forcalc) is image description

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
2

answered 2014-09-05 01:45:00 -0600

berak gravatar image

updated 2014-09-05 01:47:48 -0600

hi james, i admit, that it get's confusing, when anything is named 'moments' in one or other way ..

the 1st error is, that you forgot to create an instance of the Moments (that's the datatype) returned by moments() (that's the function creating it)

the 2nd is related to that again, don't pass the address of the function to HuMoments, but the instance created before.

so, it should be:

Moments mom = moments(image, false); 
HuMoments(mom,  hu);
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-09-05 00:44:37 -0600

Seen: 671 times

Last updated: Sep 05 '14