Finding the center of a contour using opencv and visual c++

后端 未结 3 1118
猫巷女王i
猫巷女王i 2021-01-22 18:24

I want to find the center of a contour without doing so much calculations. Is there a built in function for that in opencv?

相关标签:
3条回答
  • 2021-01-22 18:46

    Either you haven't done any research, or these questions already asked and answered here are not what you are asking:

    centroid of contour/object in opencv in c?

    OpenCV 2 Centroid

    If latter is the case, please elaborate the question in more detail.

    0 讨论(0)
  • 2021-01-22 18:51

    To answer your question:

    There is no built in function. Checkout berak for copypasta code that solves your problem.

    0 讨论(0)
  • 2021-01-22 18:52

    for the 'geometric center', get the boundingRect() of the contour, then:

       cx = br.x+br.width/2; cy = br.y+br.height/2; 
    

    for the 'center of mass' get the moments() of the contour, then:

       cx = m.m10 / m.m00;   cy = m.m01 / m.m00;
    
    0 讨论(0)
提交回复
热议问题