我正在研究一个能读取车牌的项目,我的计划是
嗯,问题是:我的代码不太好,结果太差我无法检测到矩形,下面是我的代码:
Imgproc.cvtColor(image, image, Imgproc.COLOR_BGR2GRAY, 0);
Imgproc.blur(image, image, new Size(3, 3));
Imgproc.equalizeHist(image, image);
Mat openElem = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(1, 1));
Mat closeElem = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(1, 1));
Imgproc.adaptiveThreshold(image, image, 225, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C, Imgproc.THRESH_BINARY_INV, 11, 2);
输入图片:
输出图像:
如果有经验的人会帮助我会很感激
答案 0 :(得分:2)
首先要检测图像中的印版位置,只需按照以下步骤操作:
转换为灰色
cvCvtColor(image,grayScale,CV_BGR2GRAY);
做索贝尔
Mat sobel = new Mat(grayScale.size(),CvType.CV_16S); cvSobel(grayScale,sobel,2,0,7); Mat temp = new Mat(sobel.size(),CvType.CV_8UC1); convertScaleAbs(sobel,temp,0.00390625,0);
做阈值
cvThreshold(sobel,threshold,0,255,CV_THRESH_BINARY | CV_THRESH_OTSU);
做形态学
Mat kernal = cvCreateStructuringElementEx(3,1,1,0,CV_SHAPE_RECT); cvDilate(threshold,erode_dilate,kernal,2); // X. vErode(erode_dilate,erode_dilate,kernal,4); // X. cvDilate(erode_dilate,erode_dilate,kernal,2); // X
kernal = cvCreateStructuringElementEx(1,3,0,1,CV_SHAPE_RECT); cvErode(erode_dilate,erode_dilate,kernal,1); // Y. cvDilate(erode_dilate,erode_dilate,kernal,2);
答案 1 :(得分:0)