当前位置 : 主页 > 网页制作 > HTTP/TCP >

霍夫变换做直线检测

来源:互联网 收集:自由互联 发布时间:2021-06-16
import numpy as np import cv2img = cv2.imread( ‘ 7.jpg ‘ )img =cv2.resize(img, (600, 800), interpolation= cv2.INTER_CUBIC)img = cv2.GaussianBlur(img,(3,3 ),0)gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)edges = cv2.Canny(gray,50,200,apert

 

import numpy as np
import cv2
img = cv2.imread(7.jpg)
img=cv2.resize(img, (600, 800), interpolation=cv2.INTER_CUBIC)
img = cv2.GaussianBlur(img,(3,3),0)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray,50,200,apertureSize = 3)
cv2.imwrite("canny_result.jpg", edges)
lines = cv2.HoughLinesP(edges,1,np.pi/180,100,minLineLength=90,maxLineGap=20)
print(lines.shape)
for i in range(0,lines.shape[0]):
    for x1,y1,x2,y2 in lines[i]:
        print(x1,y1,x2,y2)
        cv2.line(img,(x1,y1),(x2,y2),(0,0,255),1)
cv2.imshow("houghline",img)
cv2.waitKey()
cv2.destroyAllWindows()

 

来源:https://zhuanlan.zhihu.com/p/54468397

网友评论