我正在尝试对数独游戏进行透视变换。预期的转换仅在左侧发生。请帮我指出我的错误
输入图像:
预期输出图像:
我得到的输出:
使用cv2.approxpolydp()找到的数独谜题的各个角落如下:
top_left = [71,62]
top_right = [59, 418]
bottom_right = [443, 442]
bottom_left = [438, 29]
输出图像的形状为[300300]
相应的输出坐标为:
output_top_left = [0,0]
output_top_right = [0, 299]
output_bottom_right = [299, 299]
output_bottom_left = [299,0]
以下是我用于透视变换的代码:
#corners = [[71,62], [59, 418], [443, 442], [438, 29]]
new = np.float32([[0,0], [0,299], [299,299], [299,0]])
M = cv2.getPerspectiveTransform(np.float32(corners), new)
dst = cv2.warpPerspective(gray, M, (300,300))
生成的转换矩阵为:
[[ 9.84584842e-01 3.31882531e-02 -7.19631955e+01]
[ 8.23993265e-02 9.16380389e-01 -6.26659363e+01]
[ 4.58051741e-04 1.45318012e-04 1.00000000e+00]]
你的X,Y坐标颠倒了。Python/OpenCV要求将它们列为X,Y(即使您将它们定义为numpy值)。必须为getPerspectiveTransform指定的数组必须将它们列为X,Y
输入:
结果:
请注意:
相关问题 更多 >
编程相关推荐