Can I create a transformation matrix from rotation/translation vectors? I'm trying to deskew an image that contains an element of known size. Here's a test image:



I can use aruco::estimatePoseBoard which returns rotation and translation vectors. Is there a way to use that information to deskew everything that's in the same plane as the marker board? (Presumably by using the rotation and translation vectors to create a transformation matrix to pass to warpPerspective.)

I know how to deskew the marker board itself. What I want to be able to do is deskew the other things (in this case, the cloud-shaped object) that are 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 individual markers around the object I want to deskew and use the detected corners along with the known distance between them as input to getPerspectiveTransform. That works very well. 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.
I was stuck on the assumption that the destination points in the call to getPerspectiveTransform had to be the corners of the output image. 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&lt;Point2f&gt; 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.)