Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version
VideoCapture capture(0);

if(!capture.isOpened())
{
return (-1);
}
double width= capture.get(CV_CAP_PROP_FRAME_WIDTH);//u can get the width of the frame
double height= capture.get(CV_CAP_PROP_FRAME_HEIGHT);;//u can get the height of the frame
Mat Frame;
for( ; ; )
{
capture>> Frame;
if(!Frame.empty())
{
do what ever u want with the captured frames
}
if(waitKey(30) == 27)//since esc key ASCII Value is 27 and if it is pressed for 30 ms it will stop the camera
{
cout<<"Esc key is pressed"<<endl;
break;
}
VideoCapture capture(0);

if(!capture.isOpened())
{
return (-1);
}
double width= capture.get(CV_CAP_PROP_FRAME_WIDTH);//u can get the width of the frame
double height= capture.get(CV_CAP_PROP_FRAME_HEIGHT);;//u can get the height of the frame
Mat Frame;
for( ; ; )
{
capture>> Frame;
if(!Frame.empty())
{
do what ever u want with the captured frames
}
if(waitKey(30) == 27)//since esc key ASCII Value is 27 and if it is pressed for 30 ms it will stop the camera
{
cout<<"Esc key is pressed"<<endl;
break;
}

By default set the device Id= 0. So that automatically it will detect the camera.