相关疑难解决方法(0)

Opencv python HoughLinesP奇怪的结果

我试图获得他们在教程中为HoughLinesP过滤器获得的相同结果.我拍摄了相同的图像和相同的阈值,如下所示:

import cv2
from line import Line
import numpy as np

img = cv2.imread('building.jpg',1)
cannied = cv2.Canny(img, 50, 200, 3)
lines = cv2.HoughLinesP(cannied, 1, np.pi / 180, 80, 30, 10)


for leftx, boty, rightx, topy in lines[0]:
    line = Line((leftx, boty), (rightx,topy))
    line.draw(img, (255, 255, 0), 2)

cv2.imwrite('lines.png',img)
cv2.imwrite('canniedHouse.png',cannied)
cv2.waitKey(0)
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)

Lineclass是一个自定义类,它不会做任何有趣的事情只计算一些东西并且可以画线.然后我得到这两个图像:在此输入图像描述 在此输入图像描述

所以你可以看到我在图像的中间只有一条litle线.

不确定出了什么问题.我错过了什么?

谢谢.

python opencv houghlinesp

4
推荐指数
1
解决办法
3192
查看次数

如何检测嘈杂线条图像中的线条?

我生成带有某些线条的嘈杂图像,如下所示:

生成的图像

我正在尝试使用 OpenCV 检测线条,但出了点问题。

到目前为止,这是我的代码,包括生成嘈杂图像的代码。

import cv2
import numpy as np

def draw_random_lines(img, w, n):
    for i in range(n):
        point1 = (np.random.randint(low = 0, high = w), np.random.randint(low = 0, high = w))
        point2 = (np.random.randint(low = 0, high = w), np.random.randint(low = 0, high = w))
        cv2.line(img,point1,point2,(255,0,0),5)
    x = y = 0
    while(y<w):
        while(x<w):
            if(np.any(img[x, y] != 0)):
                if(np.random.randint(low=0, high=100) < 60):
                    img[x, y] = [255, 255, 255] 
                else:
                    img[x, y] = [0, 0, 0]
            else:
                if(np.random.randint(low=0, high=100) < …
Run Code Online (Sandbox Code Playgroud)

python opencv image-processing python-3.x

3
推荐指数
1
解决办法
3393
查看次数

Python 3.5.2:点到线的距离

我创建了一个“点”类,我想计算给定点和线(以其他 2 个点为特征)之间的最短距离,所有点都是已知的。我尝试使用这个公式:|Ax+By+C| / sqrt(A^2+B^2) ,但我搞砸了,一分钟后变得更加困惑(主要是因为数学公式:()...

我确实找到了一些人们也问这个问题的网站,但它要么不是针对 Python 的,要么是在 3D 系统中而不是 2D ...

??
下面是我的课:

class Point:
        def __init__(self,initx,inity):
            self.x = initx
            self.y = inity
        def getX(self):
            return self.x
        def getY(self):
            return self.y
        def __str__(self):
            return "x=" + str(self.x) + ", y=" + str(self.y)
        def distance_from_point(self,the_other_point):
            dx = the_other_point.getX() - self.x
            dy = the_other_point.getY() - self.y
        def slope(self,other_point):
            if self.x - other_point.getX() == 0 :
                return 0
            else:
                panta = (self.y - other_point.getY())/ (self.x - other_point.getX())
                return panta
Run Code Online (Sandbox Code Playgroud)

有人可以帮我写一个单独的函数或方法来做我想要的吗?我试了2个小时,我无法弄清楚......

python point distance line python-3.x

0
推荐指数
1
解决办法
1万
查看次数