-1

我正在尝试文档中的透视转换示例,但我得到的结果与示例不同。

import cv2
import matplotlib.pyplot as plt
import numpy as np
img = cv2.imread('sudoku.png')
rows,cols,ch = img.shape
pts1 = np.float32([[56,65],[368,52],[28,387],[389,390]])
pts2 = np.float32([[0,0],[300,0],[0,300],[300,300]])
M = cv2.getPerspectiveTransform(pts1,pts2)
dst = cv2.warpPerspective(img,M,(300,300))
plt.subplot(121),plt.imshow(img),plt.title('Input')
plt.subplot(122),plt.imshow(dst),plt.title('Output')
plt.show()

根据示例的结果应如下所示(忽略绿线) 在此处输入图像描述

而我得到的看起来像

有什么想法吗?我在 macOS 10.13、openCV 3.3.1 并使用 python 3.6

4

1 回答 1

1

你有错误的坐标。

## sudo.png (563, 558, 3)

## tl->tr->br->bl
pts1 = np.float32([[76,85],[490,70],[520,520],[35,512]])
pts2 = np.float32([[0,0],[300,0],[300,300], [0,300]])

在此处输入图像描述

于 2017-11-06T09:29:24.253 回答