无法调用cv2.HoughLines(),如何使用python代码实现cv2.HoughLines() self

问题描述

无法识别调用 cv2.houghlines()

cv2.houghlines() 将返回 rho 和 theta

那怎么用python代码实现这个cv2.houghlines with def(): self?谢谢!

#coding=utf-8
import cv2
import numpy as np  
 
img = cv2.imread("/home/sunny/workspace/images/road.jpg",0)
 
img = cv2.GaussianBlur(img,(3,3),0)
edges = cv2.Canny(img,50,150,apertureSize = 3)
lines = *cv2.houghlines*(edges,1,np.pi/180,118)
result = img.copy()
for line in lines[0]:
    rho = line[0]
    theta= line[1]
    print rho
    print theta
    if  (theta < (np.pi/4. )) or (theta > (3.*np.pi/4.0)):

        pt1 = (int(rho/np.cos(theta)),0)

        pt2 = (int((rho-result.shape[0]*np.sin(theta))/np.cos(theta)),result.shape[0])

        cv2.line( result,pt1,pt2,(255))
    else:

        pt1 = (0,int(rho/np.sin(theta)))

        pt2 = (result.shape[1],int((rho-result.shape[1]*np.cos(theta))/np.sin(theta)))

        cv2.line(result,(255),1)
 
cv2.imshow('Canny',edges )
cv2.imshow('Result',result)
cv2.waitKey(0)
cv2.destroyAllWindows()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)