简体   繁体   English

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

[英]Can I create a transformation matrix from rotation/translation vectors?

I'm trying to deskew an image that has an element of known size. 我正在尝试去掉具有已知大小元素的图像。 Given this image: 鉴于此图片:

来源图片

I can use aruco:: estimatePoseBoard which returns rotation and translation vectors. 我可以使用aruco:: estimatePoseBoard返回旋转和平移向量。 Is there a way to use that information to deskew everything that's in the same plane as the marker board? 有没有办法利用这些信息去除与标记板在同一平面上的所有东西? (Unfortunately my linear algebra is rudimentary at best.) (不幸的是,我的线性代数充其量是最基本的。)

Clarification 澄清

I know how to deskew the marker board. 我知道如何去除标记板。 What I want to be able to do is deskew the other things (in this case, the cloud-shaped object) in the same plane as the marker board. 我想要做的是在与标记板相同的平面上去除其他东西(在这种情况下,云形物体)。 I'm trying to determine whether or not that's possible and, if so, how to do it. 我正在试图确定这是否可行,如果是,那该怎么做。 I can already put four markers around the object I want to deskew and use the detected corners as input to getPerspectiveTransform along with the known distance between them. 我已经可以在我想要偏移的对象周围放置四个标记,并使用检测到的角作为getPerspectiveTransform输入以及它们之间的已知距离。 But for our real-world application it may be difficult for the user to place markers exactly. 但对于我们的实际应用,用户可能难以准确地放置标记。 It would be much easier if they could place a single marker board in the frame and have the software deskew the other objects. 如果他们可以在框架中放置单个标记板并使软件偏移其他对象,则会容易得多。

Since you tagged OpenCV: From the image I can see that you have detected the corners of all the black box. 因为你标记了OpenCV:从图像我可以看到你已经检测到所有黑盒子的角落。 So just get the most border for points in a way or another: 因此,只需以某种方式获得最多的边界: 在此输入图像描述

Then it is like this: 那就是这样的:

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

I was stuck on the assumption that the destination points in the call to getPerspectiveTransform had to be the corners of the output image (as they are in Humam's suggestion). 我坚持认为getPerspectiveTransform调用中的目标点必须是输出图像的角落(因为它们是在Humam的建议中)。 Once it dawned on me that the destination points could be somewhere within the output image I had my answer. 一旦我意识到目标点可能在输出图像中的某个地方,我得到了答案。

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

This fixed the perspective of the board and everything in its plane. 这固定了电路板的视角和平面内的一切。 (The waviness of the board is due to the fact that the paper wasn't lying flat in the original photo.) (电路板的波纹是由于纸张没有平放在原始照片中。)

纠正的观点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ICP变换矩阵平移和旋转 - ICP transformation matrix translation and rotation 如果我知道3D中的齐次变换矩阵,如何使用opencv查找旋转和平移角度? - How to find the angle of rotation and translation using opencv if I know the homogeneous transformation matrix in 3d? 从单应矩阵计算缩放、旋转和平移 - Calculating scale, rotation and translation from Homography matrix 从基本矩阵中提取翻译和轮换 - Extract Translation and Rotation from Fundamental Matrix 如何通过平移,旋转和缩放来进行仿射变换? - How do I invert an affine transformation with translation, rotation, and scaling? 我可以从这个矩阵算法中得到旋转吗 - Can i get rotation from this matrix algorithm 从本征旋转和平移矩阵创建Sophus :: SE3对象,然后返回 - Create Sophus::SE3 object from Eigen Rotation and translation matrix and go back 如何在两个不同坐标系中的对应点之间找到旋转和平移(变换矩阵) - How to find rotation and translation (transformation matrix) between corresponding points in two different coorinate systens 如何根据我的旋转和平移矩阵计算Inliers点? - how to calculate the inliers points from my rotation and translation matrix? solvePnP:获取旋转平移矩阵 - solvePnP: Obtaining the rotation translation matrix
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM