我正在使用OpenCV 2.4.3.2 for Android编写应用程序.
我的应用程序是关于车牌识别.
有几种方法可以做到,我选择做以下几点:
1.将图像转换为HSV色彩空间
2.根据车牌HSV的阈值图像(在我的国家,它们是黄色的......)
3.平滑图像高斯模糊
4.检测边缘
5.找到轮廓
6.资助houghlines
7.从houglines,检测与矩形相匹配的曲线
我被困在7,我找不到成功检测来自houglines的矩形的方法.
我非常感谢Java中的代码示例,因为大多数示例都是在C/C++中进行转换并不是那么简单.
这是我的代码(现在我只是画线......):
Imgproc.cvtColor(inputFrame, mRGBMat, Imgproc.COLOR_RGBA2BGR);
// convert HSC color space
Imgproc.cvtColor(mRGBMat, mHSVMat, Imgproc.COLOR_BGR2HSV);
// Filter out colors which are out of range (license plate hue ~ 14)
Core.inRange(mHSVMat, new Scalar(9, 70, 80, 0), new Scalar(30, 255,
255, 0), mGrayMat);
// some smoothing of the image
for (int i = 0; i < 10; i++) {
Imgproc.GaussianBlur(mGrayMat, mGrayMat, new Size(9, 9), 2, 2);
}
Mat kernel = …Run Code Online (Sandbox Code Playgroud) 我试图隔离验证码中的字母,我设法过滤了验证码,结果得到了这张黑白图像:
但是当我尝试使用 OpenCV 的 findContours 方法分离字母时,它只是发现了一个包裹我整个图像的外部轮廓,从而产生了这个图像(图像外的黑色轮廓)。
我将此代码与 Python 3 和 OpenCV 3.4.2.17 一起使用:
img = threshold_image(img)
cv2.imwrite("images/threshold.png", img)
image, contours, _ = cv2.findContours(img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
for i, contour in enumerate(contours):
area = cv2.contourArea(contour)
cv2.drawContours(img, contours, i, (0, 0, 0), 3)
cv2.imwrite('images/output3.png', img)
Run Code Online (Sandbox Code Playgroud)
我只希望我的最终结果是每个字符外有 5 个轮廓。