Orr*_*Orr 6 android opencv image-processing
我正在使用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 = 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);
}
Run Code Online (Sandbox Code Playgroud)
我以前写过这样的算法。您将线分为两种类型:1) 垂直 2) 水平 x) 要删除的异常值
然后,将这些线进一步分为两个子类型:1a) 垂直,左边框 1b) 垂直,右边框 1x) 用于删除的异常值 2a)、2b)、2x)。
得到这些线的平均斜率和截点,你就得到了你的“矩形”。
| 归档时间: |
|
| 查看次数: |
2352 次 |
| 最近记录: |