我坚持认为调用中的目标点getPerspectiveTransform
必须是输出图像的角落(就像在 Humam 的建议中一样)。一旦我意识到目标点可能在输出图像中的某个地方,我就有了答案。
float boardX = 1240;
float boardY = 1570;
float boardWidth = 1730;
float boardHeight = 1400;
vector<Point2f> destinationCorners;
destinationCorners(Point2f(boardX+boardWidth, boardY));
destinationCorners(Point2f(boardX+boardWidth, boardY+boardHeight));
destinationCorners(Point2f(boardX, boardY+boardHeight));
destinationCorners(Point2f(boardX, boardY));
Mat h = getPerspectiveTransform(detectedCorners, destinationCorners);
Mat bigImage(image.size() * 3, image.type(), Scalar(0, 50, 50));
warpPerspective(image, bigImage, h, bigImage.size());
这固定了棋盘的视角及其平面内的一切。(纸板的波纹是由于原始照片中的纸张没有平放。)
