Ask Your Question
4

How can I get frames from my webcam ?

asked 2012-06-01 09:30:37 -0500

AlexanderShishkov gravatar image

updated 2015-07-11 10:18:10 -0500

How can I do that in C++ and Python?

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted
6

answered 2012-06-01 09:31:00 -0500

AlexanderShishkov gravatar image

updated 2017-01-21 04:49:38 -0500

C++:

#include "opencv2/opencv.hpp"
using namespace cv;
int main(int argc, char** argv)
{
    VideoCapture cap;
    // open the default camera, use something different from 0 otherwise;
    // Check VideoCapture documentation.
    if(!cap.open(0))
        return 0;
    for(;;)
    {
          Mat frame;
          cap >> frame;
          if( frame.empty() ) break; // end of video stream
          imshow("this is you, smile! :)", frame);
          if( waitKey(10) == 27 ) break; // stop capturing by pressing ESC 
    }
    // the camera will be closed automatically upon exit
    // cap.close();
    return 0;
}
edit flag offensive delete link more

Comments

I tried this and frame is always empty.

diegoaguilar gravatar imagediegoaguilar ( 2013-09-05 15:36:59 -0500 )edit

This works for me. I am using openCV 3.1.0 with VS2015.

sofia123 gravatar imagesofia123 ( 2016-01-07 11:35:01 -0500 )edit

can you explain cap >> frame

marzooq6463 gravatar imagemarzooq6463 ( 2017-06-18 13:10:24 -0500 )edit

This code works for me too. I am using OpenCV 3.2.0 with visual-studio-2017

cap >> frame means the captured image will be sent to the frame which will open in a new window

blink gravatar imageblink ( 2017-07-19 04:32:32 -0500 )edit
0

answered 2016-03-26 00:59:49 -0500

openCV gravatar image

Can I get a code for the same in C language?

edit flag offensive delete link more

Comments

Something like this:

#include "cv.h"
#include "highgui.h"
int main(int argc, char** argv)
{
CvCapture* capture=0;
IplImage* frame=0;
capture = cvCaptureFromAVI("C:\\video.avi"); 
if( !capture )
    throw "Error when reading steam_avi";

cvNamedWindow( "w", 1);

for( ; ; )
{
    frame = cvQueryFrame( capture );
    if(!frame)
        break;
    cvShowImage("w", frame);
}
cvWaitKey(0); 
cvDestroyWindow("w");
cvReleaseImage(&frame);
}
AlexanderShishkov gravatar imageAlexanderShishkov ( 2016-03-28 01:49:26 -0500 )edit

Thank you so much !!! I will try this code.

openCV gravatar imageopenCV ( 2016-03-28 11:09:57 -0500 )edit

I have a small doubt. Will this code work for OMAP L138 C6748 DSP processor?

openCV gravatar imageopenCV ( 2016-03-28 23:00:57 -0500 )edit

Which version of openCV should I use for the C code mentioned above? I'm using Code Composer Studio v5.5 (CCS v5.5) as the IDE. So, what are the supporting files to be included before compiling the code. When I typed the above code in CCS, I got this error : could not open source file cv.h

openCV gravatar imageopenCV ( 2016-03-29 00:36:39 -0500 )edit

Also, I want to access an external webcam connected to OMAP L138 C6748 DSP Processor. Not the video file stored in my PC.

openCV gravatar imageopenCV ( 2016-03-29 00:39:15 -0500 )edit

If you want to get access to video camera, just use index of camera (0-based) instead of filename. Unfortunately I know nothing about CCS, you can try to use new headers:

#include "opencv2/opencv.hpp"
AlexanderShishkov gravatar imageAlexanderShishkov ( 2016-03-30 03:28:24 -0500 )edit
0

answered 2017-07-23 08:34:01 -0500

ron gravatar image

thanks worked for me ...i tried so hard and for hours. Problem was at line : if( waitKey(33) >= 0 ) break; // OpenCV book quotes it like this one

but your line is life saver

"if( waitKey(10) == 27 ) break; // stop capturing by pressing ESC " worked like charm

Regards ron

OpenCV 3.2 VStudio 2017 win10

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2012-06-01 09:30:37 -0500

Seen: 67,248 times

Last updated: Jan 21 '17