gpt4 book ai didi

Android OpenCV - 从 Houghlines 检测曲线

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:44:43 25 4
gpt4 key购买 nike

我正在使用适用于 Android 的 OpenCV 2.4.3.2 编写应用程序。
我的应用是关于车牌识别的。
有几种方法,我选择了以下方法:

1.将图像转换为HSV颜色空间
2.根据车牌HSV的阈值图像(在我的国家他们是黄色的......)
3. 用高斯模糊平滑图像
4.检测边缘
5. 寻找轮廓
6. 基金线
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);

}

最佳答案

我以前写过这样的算法。您将这些行分为两种类型:1)垂直2) 横向x) 删除异常值

然后你将这些行更多地分为两个子类型:1a) 垂直,左边框1b) 垂直,右边框1x) 删除异常值2a), 2b), 2x).

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

关于Android OpenCV - 从 Houghlines 检测曲线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15882181/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com