Quantcast
Channel: OpenCV Q&A Forum - Latest question feed
Viewing all articles
Browse latest Browse all 19555

Problem with contourArea return value

$
0
0
Hello, I'm trying to use the contourArea fonction in ordre to remove the "too small" shapes but when I'm running the above code I'm obtaining this king of results : "contour 1 color 125 area 1" or more generally "countour n color x area n". So si there someone having an idea about why I obtain the number of the contour instead of the real area delimitate by the contour ? Thank you all by advance #include #include #include #include #include #include using namespace cv; using namespace std; void drawStuff(int, void*); void showInputWindow(); void showCannyWindow(); void showContourWindow(); int lowThreshold; int const max_lowThreshold = 100; const char* window_name = "Edge Map"; int thresh = 40; int max_thresh = 120; Mat img_rgb,img_gray,img_bw,canny_output,drawing; int main(int argc, char *argv[]){ img_rgb = imread(argv[1]); blur( img_rgb, img_rgb, Size(3,3) ); namedWindow( window_name, WINDOW_AUTOSIZE ); cv::createTrackbar( "Min Threshold:", window_name, &lowThreshold, max_lowThreshold, drawStuff ); drawStuff(0,0); cv::waitKey(0); } void drawStuff(int, void*){ vector> contours; vector hierarchy; Canny( img_rgb, canny_output, lowThreshold, lowThreshold*2, 3 ); cv::dilate(canny_output, canny_output, cv::Mat(), cv::Point(-1,-1)); showCannyWindow(); findContours( canny_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) ); drawing = Mat::zeros( canny_output.size(), CV_8UC3 ); vector approxShape; vector areas; for(size_t i = 0; i < contours.size(); i++){ approxPolyDP(contours[i], approxShape, arcLength(Mat(contours[i]), true)*0.04, true); areas.push_back(contourArea(contours[i],false)); drawContours(drawing, contours, i, Scalar((i+1)*10%255, (i+1)*10%255, (i+1)*10%255), CV_FILLED); // fill one gray per contour printf("contour %d color %d area%d\n",i,(i+i)*10%255,areas[i]); } //cv::fastNlMeansDenoising(img_rgb,contours,3,7,21); showContourWindow(); } void showInputWindow(){ cv::namedWindow("InputImage"); cv::imshow("InputImage",img_rgb); } void showCannyWindow(){ cv::namedWindow("Canny"); cv::imshow("Canny",canny_output); } void showContourWindow(){ cv::namedWindow("Fill"); cv::imshow("Fill",drawing); }

Viewing all articles
Browse latest Browse all 19555

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>