1 回答
TA贡献1860条经验 获得超8个赞
一种方法是使用霍夫变换来检测线并获得每条线的角度。然后可以通过减去两条线之间的差来找到两条线之间的角度。
我们首先使用算术平均来np.mean对导致此结果的图像进行阈值处理。
image = cv2.imread('2.png')
# Compute arithmetic mean
image = np.mean(image, axis=2)
现在我们执行skimage.transform.hough_line检测线
# Perform Hough Transformation to detect lines
hspace, angles, distances = hough_line(image)
# Find angle
angle=[]
for _, a , distances in zip(*hough_line_peaks(hspace, angles, distances)):
angle.append(a)
接下来我们获得每条线的角度并找到差异以获得我们的结果
# Obtain angle for each line
angles = [a*180/np.pi for a in angle]
# Compute difference between the two lines
angle_difference = np.max(angles) - np.min(angles)
print(angle_difference)
16.08938547486033
完整代码
from skimage.transform import (hough_line, hough_line_peaks)
import numpy as np
import cv2
image = cv2.imread('2.png')
# Compute arithmetic mean
image = np.mean(image, axis=2)
# Perform Hough Transformation to detect lines
hspace, angles, distances = hough_line(image)
# Find angle
angle=[]
for _, a , distances in zip(*hough_line_peaks(hspace, angles, distances)):
angle.append(a)
# Obtain angle for each line
angles = [a*180/np.pi for a in angle]
# Compute difference between the two lines
angle_difference = np.max(angles) - np.min(angles)
print(angle_difference)
添加回答
举报