Reputation: 1230
Is it even possible to draw a rectangle over multiple frame?
Let me explain a bit. I have a tall box i wanted draw a rectangle over that box, but the problem the box is too big to fit inside a frame. I know the exact dimension of the box and how far away am from the box. Now i wanted to move my camera from top to bottom so that i can see the full rectangle over the box.
Upvotes: 0
Views: 530
Reputation: 8607
I'm not sure if I understand your question, but these are my two cents.
I assume you have a frame, which is an image in a cv::Mat
, that shows an object (a box) and you want to draw a rectangle around it. You know the 2D coordinates of the object in your image. Then, you can draw a rectangle like this:
cv::rectangle(image, cv::Point(x1, y1), cv::Point(x2, y2), cv::Scalar(255, 0, 0));
Where x1 y1
and x2 y2
are two opposite corners of the rectangle to show, and the cv::Scalar
is the color (red if your image is CV_8UC3
).
When you move the camera, I assume that you recompute the 2D coordinates of your object in the new image. Then, you have to redraw the rectangle again. The final code should be something similar to this:
while (true) {
cv::Mat image = getImageFromCamera();
cv::Point corner1, corner2;
computeRectangleCoordinates(corner1, corner2);
// draw
cv::rectangle(image, corner1, corner2, cv::Scalar(255, 0, 0));
// display
cv::imshow("box", image);
cv::waitKey(5);
}
Upvotes: 1
Reputation: 50657
One simple way is first merge/combine these frames into a larger frame (larger than the box), and then draw the box on this combined frame.
If you need to get each small frame with box drawn, you can further extract the ROI from the combined frame.
Upvotes: 0