【图像处理】初等的直线检测算法

2024-10-18 23:08:37

1、线用Canny算子检测图像的边界。img0=cv2.imread('0.png')img=cv2.Canny(img0,0,255)

【图像处理】初等的直线检测算法

3、画出像素最多的直线:R,葡矩酉缸m1=np.where(acc==np.max(acc))A=[]for i in range(u)多唉捋胝: for j in range(v): if img[i,j]!=0: for m in range(1,180): m0=m*np.pi/180 h=int(j*np.cos(m0)+i*np.sin(m0)) if h==R and m==m1: A.append((j,i))cv2.line(img0,A[0],A[-1],(0,0,255),2)

【图像处理】初等的直线检测算法

5、opencv内置的检测直线的算子速度很快:img0=cv2.imread('0.png')lines = cv2.HoughLinesP(img, 1, np.pi/180, 80,30,10)for x1, y1, x2, y2 in lines[0]: cv2.line(img0, (x1, y1), (x2, y2), (0,255,0), 2)cv2.imwrite('2.png',img0)

【图像处理】初等的直线检测算法【图像处理】初等的直线检测算法
猜你喜欢