线检测|使用Java进行角度检测 [英] Line detection | Angle detection with Java

查看:305
本文介绍了线检测|使用Java进行角度检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理我的UGV(Unmanned Ground Vehichle)捕获的一些图像,以使其在一条线上移动。

I'm processing some images that my UGV (Unmanned Ground Vehichle) captures to make it move on a line.

我想得到该线的角度立足于地平线。我将尝试用几个例子来解释:

I want to get the angle of that line based on the horizon. I'll try to explain with a few examples:

上面的图像会使我的UGV保持笔直向前,角度约为90度。
但是下面会让它向左转,因为角度与地平线相比约为120.

The image above would make my UGV to keep straight ahead, as the angle is about 90 degrees. But the following would make it turn left, as the angle compaired to the horizon rounds about 120.

我可以使用otsu成功地将这些图像转换为下面的图像进行阈值处理:

I could successfully transform those images into the image below using otsu for thresholding:

并且还使用边缘检测算法来实现:

And also used an edge detection algorithm to get this:

但是我现在正试图找到一个能够检测那些边缘/线和输出的算法 - 或者帮助我输出 - 这条线的角度..

But I'm stuck right now trying to find an algorithm that detecs those edges/lines and outputs - or helps me to output - the angle of such line..

推荐答案

这是我尝试使用ImageJ:

Here's my attempt using ImageJ:

    // Open the Image
ImagePlus image = new ImagePlus(filename);

    // Make the Image 8 bit
IJ.run(image, "8-bit", "");

    // Apply a Threshold (0 - 50)
ByteProcessor tempBP = (ByteProcessor)image.getProcessor();
tempBP.setThreshold(0, 50, 0);
IJ.run(image, "Convert to Mask", "");

    // Analyze the Particles
ParticleAnalyzer pa = new ParticleAnalyzer(
    ParticleAnalyzer.SHOW_MASKS +
    ParticleAnalyzer.IN_SITU_SHOW,
    1023 +
    ParticleAnalyzer.ELLIPSE
    , rt, 0.0, 999999999, 0, 0.5);

IJ.run(image, "Set Measurements...", "bounding fit redirect=None decimal=3");

pa.analyze(image);

int k = 0;
double maxSize = -1;
for (int i = 0; i < rt.getCounter(); i ++) {
    // Determine creteria for best oval.
    // The major axis should be much longer than the minor axis.
    // let k = best oval
}
double bx = rt.getValue("BX", k);
double by = rt.getValue("BY", k);
double width = rt.getValue("Width", k);
double height = rt.getValue("Height", k);

// Your angle:
double angle = rt.getValue("Angle", k);
double majorAxis = rt.getValue("Major", k);
double minorAxis = rt.getValue("Minor", k);

代码如何运作:


  1. 使图像灰度化。

  2. 在其上应用阈值以仅获取暗区。这假设线条总是接近黑色。

  3. 应用粒子分析器在图像上找到椭圆。

  4. 循环通过粒子到找到符合我们标准的。

  5. 从我们的粒子中获取角度。

  1. Make the image grayscaled.
  2. Apply a threshold on it to only get the dark areas. This assumes the lines will always be near black.
  3. Apply a Particle Analyzer to find Ellipses on the image.
  4. Loop through the "Particles" to find ones that fit our criteria.
  5. Get the angle from our Particle.

这是一个我分析时图像的样子示例:

Here's an example of what the image looks like when I analyze it:


注意:代码未经测试。我刚刚将Visual ImageJ中的内容转换为Java。

NOTE: The code is untested. I just converted what I did in the Visual ImageJ into Java.

这篇关于线检测|使用Java进行角度检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆