如何获得仪表的轮廓区域?

时间:2013-04-29 10:39:12

标签: c++ opencv contour

这是我找到二进制图像轮廓区域的代码:

std::vector< std::vector<cv::Point> > contours_temp;

cv::Mat temp = map_;
cv::Mat Expanded_Map;
cv::Mat Contour_map;
std::vector<cv::Vec4i> hierarchy;

for ( int i = 0 ; i < 1.5  / map_resolution_ ; i++ )
{
    cv::erode(temp, Expanded_Map, cv::Mat(), cv::Point(-1,-1), 1);
    cv::imshow("Expanded Map", Expanded_Map );
    temp = Expanded_Map;
    Contour_map = Expanded_Map.clone();

    cv::findContours( Contour_map , contours_temp , hierarchy , CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE );
    cv::drawContours( Contour_map , contours_temp, -1, cv::Scalar( 128 , 128 , 128 , 128 ), 2);
    cv::line( Contour_map , convertFromMeterToPixelCoordinates<cv::Point>(Pose(1.f,0.2f,0.f)), convertFromMeterToPixelCoordinates<cv::Point>(Pose(-1.f,0.2f,0.f)), cv::Scalar(0,0,0,0), 2);
    cv::imshow("contour areas new", Contour_map);

    std::cout<<"\nContour size: "<<contours_temp.size()<<"\n";

    for( int idx = 0 ; idx >= 0; idx = hierarchy[idx][0] )
    {
        double area = cv::contourArea(contours_temp[idx]);

        std::cout << "area[" << idx << "]: "<< area << std::endl;
    }

    cv::waitKey();
}

我希望以米为单位获取轮廓区域,而不是以像素为单位。

double area = cv::contourArea(contours_temp[idx]);

图像分辨率= 0.05

任何想法?

0 个答案:

没有答案