我可以根据旋转/平移向量创建变换矩阵吗?

时间:2016-01-29 03:01:08

标签: c++ opencv matrix aruco

我试图去掉一个已知大小元素的图像。鉴于此图片:

Source image

我可以使用aruco:: estimatePoseBoard返回旋转和平移向量。有没有办法利用这些信息来纠正与标记板在同一平面上的所有东西? (不幸的是,我的线性代数充其量只是基本的。)

澄清

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

2 个答案:

答案 0 :(得分:2)

由于您标记了OpenCV: 从图像中我可以看到你已经检测到所有黑匣子的角落。因此,只需以某种方式获得最多的边界: enter image description here

然后是这样的:

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));

答案 1 :(得分: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());

这修正了电路板的视角和平面内的一切。 (电路板的波纹是由于纸张在原始照片中没有平放的原因。)

corrected perspective

相关问题