【问题标题】:Android OpenCV - detect curves from HoughlinesAndroid OpenCV - 从 Houghlines 检测曲线
【发布时间】: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


【解决方案1】:

我以前写过这样的算法。您将线条分为两种类型: 1) 垂直 2) 水平 x) 要删除的异常值

然后您将这些行进一步分为两个子类型: 1a) 垂直,左边框 1b) 垂直,右边框 1x)要删除的异常值 2a)、2b)、2x)。

得到这些线的平均斜率和截点,你就有了你的“矩形”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多