Ask Your Question
0

Setting up a camera system to use with OpenCV

asked 2013-06-24 14:54:57 -0600

JDS gravatar image

Hello,

Probably a dumb/basic question, apologies in advance.

I want to buy a standard webcam, say something like this: http://www.bestbuy.com/site/Logitech+-+HD+Webcam+C615/2588445.p;jsessionid=3665222F1C297C76927E29F770068174.bbolsp-app02-163?id=1218337862339&skuId=2588445

Then I want to connect it to my laptop and use OpenCV to analyze its video feed to run CV algorithms with. What do I need to do to get started with this task? Just the set-up so in my C++ code I have the video stream available to analyze. Is there some basic template code I could get started with?

Thanks!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2013-06-24 15:05:53 -0600

berak gravatar image

this should get you started:

#include "opencv2/opencv.hpp"
int main(int argc, char **argv)
{    
    Mat img;
    VideoCapture cap(0); // 1st cam
    while(cap.isOpenend())
    {
        cap >> img;
        if ( !img.empty() )
        {
            // your processing code here
            imshow("image", img); 
        }
        char k = (char) waitKey(10); // sleep for 10 millis
        if ( k == 27 ) break; // 'esc' pressed
    }
    return 0;
}
edit flag offensive delete link more

Comments

Thank you. Two quick q's: will VideoCapture cap(0); grab the camera stream of a generic webcam plugged in via USB - and cap(1) the second one then? And in your code, what is the purpose of sleeping for 10 milliseconds?

JDS gravatar imageJDS ( 2013-06-24 20:29:51 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2013-06-24 14:54:57 -0600

Seen: 1,573 times

Last updated: Jun 24 '13