简体   繁体   English

Android OpenCV - 获取两条模糊线之间的距离

[英]Android OpenCV - Getting distance between two indistinct lines

As mentioned, I'm trying to get the distance between two indistinct lines from an image with applied edge detection.如前所述,我试图从应用边缘检测的图像中获取两条模糊线之间的距离。 As an example please look at the below image for clarification.作为示例,请查看下图以进行说明。

在此处输入图像描述

As you can see, the lines are misshaped.如您所见,线条形状不正确。 Ideally what I would like is to get the furthest points from each line as displayed above, and calculate their distance from that.理想情况下,我想要的是从上面显示的每条线中获取最远的点,并计算它们之间的距离。 Is this possible with OpenCV? OpenCV 可以做到这一点吗? I know I can use the magnitude function to calculate the distance appropriately, but the issue comes with actually trying to find the furthest points in the first place.我知道我可以使用幅度 function 来适当地计算距离,但问题在于实际上首先要找到最远的点。

Would anyone have an idea as to how I might go about this?有没有人知道我会如何 go 关于这个?

If you know two points on those lines then you can calculate the distance using below code in OpenCV.如果您知道这些线上的两个点,那么您可以使用 OpenCV 中的以下代码计算距离。

public double euclideanDistance(Point a, Point b){
    double distance = 0.0;
    try{
        if(a != null && b != null){
            double xDiff = a.x - b.x;
            double yDiff = a.y - b.y;
            distance = Math.sqrt(Math.pow(xDiff,2) + Math.pow(yDiff, 2));
        }
    }catch(Exception e){
        System.err.println("Something went wrong in euclideanDistance function in "+Utility.class+" "+e.getMessage());
    }
    return distance;
}

I hope this helps.我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM