0
// computing hu moments
  Moments moments2=moments(croppedImage,false);
  double hu[7];
  HuMoments(moments2,hu);

this code gives the hu moment for the contours. Can any body provide the equivalent code in Emgucv C#?

partial C# code

 MCvMoments moments = contours.GetMoments();
 MCvHuMoments Humoments;
 CvInvoke.cvGetHuMoments(moments,.........);

struggling with 2nd parameter for cvGetHuMoments method.

sjy
  • 61
  • 3
  • 12

2 Answers2

0
Contour<Point> contours = image.FindContours();    
MCvMoments moments = contours.GetMoments();
MCvHuMoments huMoments.GetHuMoment();

The MCvHuMoments structure has fields to get hu1 to hu7.

rold2007
  • 1,297
  • 1
  • 12
  • 25
  • in moments i am getting moments but can you elaborate more to get all 7 hu moments in one array. thank you – sjy May 12 '14 at 12:13
  • The McvHuMoment structure doesn't allow to extract an array of hu moments directly. But you could marshal the struct to an array like it is explained in these answers: http://stackoverflow.com/questions/3278827/how-to-convert-a-structure-to-a-byte-array-in-c and http://stackoverflow.com/questions/2871/reading-a-c-c-data-structure-in-c-sharp-from-a-byte-array – rold2007 May 12 '14 at 22:02
  • getting error in statement MCvHuMoments huMoments.GetHuMoments(); – sjy May 14 '14 at 17:35
  • i need humoments using any method,in array or diffrent variable for each moment it is fine for me. reply plz thank you! – sjy May 14 '14 at 17:37
  • @sjy I guess you find your problem since you accepted this answer. Probably your huMoments was null ? – rold2007 May 15 '14 at 20:18
  • :: using (MemStorage storage = new MemStorage()) { Contour contours = grayImage.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE, Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_TREE, storage); while (contours != null) { MCvMoments moments = contours.GetMoments(); MCvHuMoments huMoments.GetHuMoments();}} in last line of code i am getting error – sjy May 20 '14 at 07:01
  • I thought you had an execution error but now I understand that you have a compilation error. I was my mistake, GetHuMoment() doesn't take a 's' at the end, I edited my answer accordingly. – rold2007 May 24 '14 at 04:45
  • Nope here in MCvHuMoments huMoments.GetHuMoment(); you are not giving any reference of contours then how it is computing the humoments for contours? still your solution is not working for me:( – sjy May 29 '14 at 06:13
  • i edited my question may question.may be it can help you to get where i got stuck. – sjy May 29 '14 at 06:53
0
MCvMoments Moments = CvInvoke.Moments(myImg);

VectorOfDouble HU_Moments = new VectorOfDouble();

CvInvoke.HuMoments(Momenti, HU_Moments);

double[] momentsD = HU_Moments.ToArray();
krjw
  • 4,070
  • 1
  • 24
  • 49
Filos
  • 1
  • Remember that Stack Overflow isn't just intended to solve the immediate problem, but also to help future readers find solutions to similar problems, which requires understanding the underlying code. This is especially important for members of our community who are beginners, and not familiar with the syntax. Given that, **can you [edit] your answer to include an explanation of what you're doing** and why you believe it is the best approach? – Jeremy Caney Apr 14 '22 at 02:13