1 | initial version |
you can find biggest contour and analyze it with Contour Approximation here my sample code that you can adopt it to python
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
static bool analyzeImage( const Mat& image )
{
Mat gray,gray0;
vector<vector<Point> > contours;
cvtColor(image,gray0,COLOR_BGR2GRAY);
gray=gray0 > 10 ;
// find contours and store them all as a list
findContours(gray, contours, RETR_LIST, CHAIN_APPROX_SIMPLE);
for( size_t i = 0; i < contours.size(); i++ )
{
approxPolyDP(Mat(contours[i]), contours[i], 5, true);
if( fabs(contourArea(Mat(contours[i]))) > image.rows*image.cols/3 )
{
Scalar color;
String Message;
if( contours[i].size() >5) // here we test if the biggest contour have 4 or more corner
{
color = Scalar(255,127,0);
Message = "Dents" ;
}
else
{
color = Scalar(0,255,0);
Message = "No Dents" ;
}
drawContours( image,contours,i, color ,2 );
putText(image, Message, Point(image.cols/5,image.rows/2),FONT_HERSHEY_PLAIN, 2.5, CV_RGB(255,255,255), 2.0);
imshow("image",image);
waitKey();
return true;
}
}
return false;
}
int main( int argc, char** argv )
{
Mat image = imread(argv[1], 1);
if( image.empty() )
{
cout << "Could not open or find the image" << endl ;
return -1;
}
if( !analyzeImage(image) );
{
cout << "Could not find any result" << endl ;
return -1;
}
return 0;
}