c++ - Principle range of object orientation using image moments -


i trying extract angle of shape in image using moments in opencv/c++. able extract angle, issue principal range of angle 180 degrees. makes orientation of object ambiguous respect 180 degree rotations. code using extract angle is,

findcontours(frame, contours, cv_retr_external, cv_chain_approx_simple);  vector<vector<point2i> > hull(contours.size());  int maxarea = 0; int maxi = -1;  int m20 = 0; int m02 = 0; int m11 = 0;  (int = 0; < contours.size(); i++) {     convexhull(contours[i], hull[i], false);     approxpolydp(hull[i], contourvertices, arclength(hull[i], true)*0.1, true);     shapemoments = moments(hull[i], false);      if(shapemoments.m00 <= areathreshold || shapemoments.m00 >= max_area)         continue;      if(contourvertices.size() <= 3 || contourvertices.size() >= 7)         continue;      if(shapemoments.m00 >= maxarea)     {         maxarea = shapemoments.m00;         maxi = i;     } }  if(maxi == -1)     return false;  fabriccontour = hull[maxi];  approxpolydp(hull[maxi], contourvertices, arclength(hull[maxi], true)*0.02,true); shapemoments = moments(hull[maxi], false); centerofmass = point2f(shapemoments.m10/shapemoments.m00, shapemoments.m01/shapemoments.m00);  drawcontours(contourframe, hull, maxi, scalar(24, 35, 140), cv_filled, cv_aa); drawcontours(originalframe, hull, maxi, scalar(255, 0, 0), 8, cv_aa); circle(contourframe, centerofmass, 4, scalar(0, 0, 0), 10, 8, 0);  posx = centerofmass.x; posy = centerofmass.y; m11 = shapemoments.mu11/shapemoments.m00; m20 = shapemoments.mu20/shapemoments.m00; m02 = shapemoments.mu02/shapemoments.m00; num = double(2)*m11; den = m20 - m02; angle = (int(-1*(180/(2*m_pi))*atan2(num, den)) + 45 + 180)%180; //angle = int(-1*(180/(2*m_pi))*atan2(num, den));  area = shapemoments.m00; 

is there way can remove ambiguity extracted angle? tries using third order moments, not seem reliable.


Comments

Popular posts from this blog

What Are The Best Universities In The World?

The Ten Most Livable Cities In The World

Hard vs. Soft Water: What's The Difference?