6

我正在尝试歪斜具有已知大小元素的图像。鉴于此图像:

源图像

我可以使用aruco:: estimatePoseBoardwhich 返回旋转和平移向量。有没有办法使用该信息来校正与标记板在同一平面上的所有内容?(不幸的是,我的线性代数充其量只是初级的。)

澄清

我知道如何歪斜标记板。我想要做的是将其他东西(在这种情况下,云形物体)与标记板放在同一平面上。我正在尝试确定这是否可行,如果可以,该怎么做。我已经可以在我想歪斜的对象周围放置四个标记,并使用检测到的角作为输入getPerspectiveTransform以及它们之间的已知距离。但是对于我们的实际应用程序,用户可能很难准确地放置标记。如果他们可以在框架中放置一个标记板并让软件对其他对象进行纠偏,那就容易多了。

4

2 回答 2

2

由于您标记了 OpenCV:从图像中我可以看到您已经检测到所有黑盒的角。因此,只需以某种方式获得点的最大边界: 在此处输入图像描述

然后是这样的:

std::vector<cv::Point2f> src_points={/*Fill your 4 corners here*/};
std::vector<cv::Point2f> dst_points={cv:Point2f(0,0), cv::Point2f(width,0), cv::Point2f(width,height),cv::Point2f(0,height)}; 
auto H=v::getPerspectiveTransform(src_points,dst_points);
cv::Mat copped_image;
cv::warpPerspective(full_image,copped_image,H,cv::Size(width,height));
于 2016-01-29T08:41:53.343 回答
1

我坚持认为调用中的目标点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());

这固定了棋盘的视角及其平面内的一切。(纸板的波纹是由于原始照片中的纸张没有平放。)

矫正透视

于 2016-02-17T01:57:18.320 回答