posted by 심재형 2017. 11. 15. 13:43

matchShapes

Compares two shapes.

C++: double matchShapes(InputArray contour1, InputArray contour2, int method, double parameter)
Python: cv2.matchShapes(contour1, contour2, method, parameter) → retval
C: double cvMatchShapes(const void* object1, const void* object2, int method, double parameter=0 )
Python: cv.MatchShapes(object1, object2, method, parameter=0) → float
Parameters:
  • object1 – First contour or grayscale image.
  • object2 – Second contour or grayscale image.
  • method – Comparison method: CV_CONTOURS_MATCH_I1 , CV_CONTOURS_MATCH_I2 or CV_CONTOURS_MATCH_I3 (see the details below).
  • parameter – Method-specific parameter (not supported now).

The function compares two shapes. All three implemented methods use the Hu invariants (see HuMoments() ) as follows ( A denotes object1,:math:B denotes object2 ):

  • method=CV_CONTOURS_MATCH_I1

    I_1(A,B) =  \sum _{i=1...7}  \left |  \frac{1}{m^A_i} -  \frac{1}{m^B_i} \right |

  • method=CV_CONTOURS_MATCH_I2

    I_2(A,B) =  \sum _{i=1...7}  \left | m^A_i - m^B_i  \right |

  • method=CV_CONTOURS_MATCH_I3

    I_3(A,B) =  \max _{i=1...7}  \frac{ \left| m^A_i - m^B_i \right| }{ \left| m^A_i \right| }

where

\begin{array}{l} m^A_i =  \mathrm{sign} (h^A_i)  \cdot \log{h^A_i} \\ m^B_i =  \mathrm{sign} (h^B_i)  \cdot \log{h^B_i} \end{array}

and h^A_i, h^B_i are the Hu moments of A and B , respectively.