2024-05-16 14:06:01 发布
网友
我想知道拉环的角度,但我还不能。你知道吗
用opencvpython做这个有什么想法吗?你知道吗
你可以试着用HoughLinesP()来找出那条线,然后计算出这条线的角度。如果需要旋转图像,则可以将其传递给ndimage.rotate():
HoughLinesP()
ndimage.rotate()
import numpy as np import cv2 import math from scipy import ndimage img_before = cv2.imread('find_angle.jpg') img_gray = cv2.cvtColor(img_before, cv2.COLOR_BGR2GRAY) img_edges = cv2.Canny(img_gray, 100, 100, apertureSize=3) lines = cv2.HoughLinesP(img_edges, 1, math.pi / 180.0, 100, minLineLength=80, maxLineGap=5) angles = [] for x1, y1, x2, y2 in lines[0]: cv2.line(img_before, (x1, y1), (x2, y2), (255, 0, 0), 3) angle = math.degrees(math.atan2(y2 - y1, x2 - x1)) angles.append(90 + angle) median_angle = np.median(angles) img_rotated = ndimage.rotate(img_before, median_angle) cv2.imshow("Result", img_rotated) key = cv2.waitKey(0) cv2.imwrite('rotated.jpg', img_rotated)
这将为您提供使用11.876角度的输出图像:
11.876
不过,对于其他图像,这种方法还需要进一步调整。你知道吗
你可以试着用
HoughLinesP()
来找出那条线,然后计算出这条线的角度。如果需要旋转图像,则可以将其传递给ndimage.rotate()
:这将为您提供使用
11.876
角度的输出图像:不过,对于其他图像,这种方法还需要进一步调整。你知道吗
相关问题 更多 >
编程相关推荐