Calculate the area of an object with OpenCV

前端 未结 1 906
一整个雨季
一整个雨季 2020-12-15 11:01

I need to calculate the area of a blob/an object in a grayscale picture (loading it as Mat, not as IplImage) using OpenCV. I thought it would be a good idea to get

相关标签:
1条回答
  • 2020-12-15 11:34

    contours is actually defined as

    vector<vector<Point> > contours;
    

    And now I think it's clear how to access its points.

    The contour area is calculated by a function nicely called contourArea():

    for (unsigned int i = 0;  i < contours.size();  i++)
    {
         std::cout << "# of contour points: " << contours[i].size() << std::endl;
    
         for (unsigned int j=0;  j<contours[i].size();  j++)
         {
             std::cout << "Point(x,y)=" << contours[i][j] << std::endl;
         }
    
         std::cout << " Area: " << contourArea(contours[i]) << std::endl;
    }
    
    0 讨论(0)
提交回复
热议问题