Rwy5
Rwy5

Reputation: 23

Shape Detection using OpenCV from live video stream

In this post, topic of shape detection (from images) in OpenCV considered. To extend the topic, how it is possible to detect shapes by OpenCV from a live video stream in real time?

Upvotes: 0

Views: 1435

Answers (1)

Rachel L
Rachel L

Reputation: 327

Yes, it is possible to detect shapes using OpenCV from a video stream - as Miki mentioned, VideoCapture and grabbing each frame as a single image would be the way to do that. Code for that in C++ would be something like:

//inside your method, make sure to bring in the libraries needed
VideoCapture capture(0); //opens the first webcam on your computer
Mat frame;

while (true) { 
    capture >> frame; //pulls the next frame in
    if (frame.empty()) { //makes sure it's not empty
    printf("No frame!");
    break;}
    //do whatever you want with that frame here
    imshow("framename", frame); //displays the frame to the user
    waitKey(1); //longer gives you a longer delay between frames
}

Doing it in real-time is a little more difficult - depending on how fast the frame-rate on the camera and how powerful the computer processing the program is, you can trim the update rate down to fractions of a second. If it's still not fast enough, going through the opencv cuda or opencv gpu libraries might get you the faster speed that you need.

Upvotes: 2

Related Questions