Reputation:
Basically I need to capture the video from videocamera do some processing on frames and for each frame show a rectangle of detection.
Example: http://www.youtube.com/watch?v=aYd2kAN0Y20
How would you superimpose this rectangle on the output of videocamera (usb)? (c++)
Upvotes: 1
Views: 1636
Reputation: 5133
I would use OpenCV, an open source imaging library to get input from a webcam/video file. Here is a tutorial on how to install it:
http://opensourcecollection.blogspot.com.es/2011/04/how-to-setup-opencv-22-in-codeblocks.html
Then I would use this code:
CvCapture *capture = cvCreateCameraCapture(-1);
IplImage* frame = cvQueryFrame(capture);
To get the image, frame
from the CvCapture
, capture
.
In this case, capture
is taken directly from a video camera, but you can also create it from a video file with:
CvCapture *capture = cvCreateFileCapture("filename.avi");
Then, I would draw on the image with functions defined here: http://opencv.willowgarage.com/documentation/drawing_functions.html
By the way, the shape in the Youtube video is not a rectangle. It's a parallelogram.
If you want to do it live, then you can basically put this in a loop, getting a frame, processing it, drawing on it, and then outputting the image, like this:
You would include this before your loop:
cvNamedWindow("Capture", CV_WINDOW_AUTOSIZE);
And then, in your loop, you would say this:
cvShowImage("Capture", frame);
After the processing.
EDIT To do this in C++, open your webcam like this:
VideoCapture cap(0); // open the default camera
if(!cap.isOpened()) // check if we succeeded
return -1;
To initialize it from a file, instead of putting in the camera index, put the file path.
Get a frame from the camera like this:
Mat frame;
cap >> frame; // get a new frame from camera
Then you can find drawing functions here: http://opencv.willowgarage.com/documentation/cpp/core_drawing_functions.html
Cheers!
Upvotes: 3