Reputation: 801
I'm new to using OpenCV and i'm testing it out trying to grab a licence plate from a car. I'm stuck on how to go about doing that. For example i will start off with an image like this:
and i want my final result to be something like:
I know how to use adaptivethreshold and things i'm confused at the steps need to go from 1 to 2. Thanks for the help!
Upvotes: 0
Views: 375
Reputation: 7502
This is exactly what you want - https://github.com/MasteringOpenCV/code/tree/master/Chapter5_NumberPlateRecognition
Its from the Mastering OpenCV Book. It segments number plates as well as dopes rudimentary OCR to recognise characters.
Upvotes: 0
Reputation: 5708
too many hardcoded thresholds but will this work?
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace cv;
int main( int argc, char** argv )
{
Mat src = imread( "C:/test/single/license.jpg");
cvtColor(src,src,CV_BGR2GRAY);
blur( src, src, Size(3,3) );
Canny( src, src, 130, 130*4, 3 );
imshow( "edge", src );
GaussianBlur(src,src,Size(3,3),60);
threshold(src,src,0,255,CV_THRESH_OTSU);
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
findContours(src, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
Mat todraw=Mat::zeros(src.size(), CV_8UC1);
for(size_t i = 0; i < contours.size(); i++)
{
double area = fabs(contourArea(Mat(contours[i])));
if(area<600)
drawContours(todraw,contours,i,Scalar(255),-1);
}
imshow( "plate", todraw );
waitKey(0);
return 0;
}
Upvotes: 1