【发布时间】:2013-03-30 17:12:11
【问题描述】:
我正在使用适用于 Android 的 OpenCV 2.4.3.2 编写应用程序。
我的应用是关于车牌识别的。
有几种方法可以做到,我选择了以下方法:
1. 将图像转换为 HSV 颜色空间
2. 根据车牌 HSV 的阈值图像(在我的国家它们是黄色的......)
3. 使用高斯模糊平滑图像
4. 检测边缘
5. 寻找轮廓
6. 基金周线
7. 从 houglines 中,检测与矩形匹配的曲线
我被困在 7 点,我无法找到一种方法来成功地检测出矩形的矩形。
我非常感谢 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 = Imgproc.getStructuringElement(Imgproc.MORPH_DILATE,
new Size(3, 3), new Point(1, 1));
Imgproc.Canny(mGrayMat, mGrayMat0, 48, 120);
Imgproc.dilate(mGrayMat0, mGrayMat0, kernel);
kernel.release();
List<MatOfPoint> contours = new Vector<MatOfPoint>();
Imgproc.findContours(mGrayMat0, contours, mHirerchy,
Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
Mat lines = new Mat(); // finds houghlines in the contours
Imgproc.HoughLinesP(mGrayMat0, lines, 1, Math.PI / 180, 1);
for (int x = 0; x < lines.cols(); x++) {
double[] vec = lines.get(0, x);
double x1 = vec[0], y1 = vec[1], x2 = vec[2], y2 = vec[3];
Point start = new Point(x1, y1);
Point end = new Point(x2, y2);
Core.line(mRgba, start, end, RECT_COLOR, 1);
}
【问题讨论】:
标签: android opencv image-processing