霍夫直线变换
霍夫直线变换(Hough Line Transform)用来做直线检测
为了加升大家对霍夫直线的理解,我在左图左上角大了一个点,然后在右图中绘制出来经过这点可能的所有直线
绘制经过某点的所有直线的示例代码如下,这个代码可以直接拷贝运行
import cv2 as cv
import matplotlib.pyplot as plt
import numpy as npdef draw_line():# 绘制一张黑图img = np.zeros((500, 500, 1), np.uint8)# 绘制一个点cv.line(img, (10, 10), (10, 10), (255), 1)cv.imshow("line",img)return imgdef hough_lines(img):rho = 1;theta = np.pi/180threshold=0lines = cv.HoughLines(img,rho, theta, threshold)dst_img = img.copy()for line in lines[:,0]:rho,theta = linea = np.cos(theta)b = np.sin(theta)x = a*rhoy=b*rhox1 =