How can I get frames from my webcam ?
How can I do that in C++ and Python?
How can I do that in C++ and Python?
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;
}
Can I get a code for the same in C language?
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);
}
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
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"
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
Asked: 2012-06-01 09:30:37 -0600
Seen: 93,390 times
Last updated: Jan 21 '17
OpenCV can't capture the frame from the webcam.
How to use a camera to get single frames?
autogain. how to disable autogain and set a fixed value
Computer Vision - Craps Coach Project from a Newbie
Camera is not working in OpenCV on Ubuntu 12.04 with version 2.3.1 or 2.4.2
Reading pixel values from a frame of a video
How to set resolution of video capture in python with Logitech c910 & c920
VideoCapture open and source switching problems [closed]
VideoCapture parameters CV_CAP_PROP_FOURCC or CV_CAP_PROP_FPS, among others, not working