#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
#if 1
{
// opencv 1 style
CvCapture* capture = 0;
Mat frame, frameCopy, image;
capture = cvCaptureFromCAM( 0 ); //0=default, -1=any camera, 1..99=your camera
if(!capture) cout << "No camera detected" << endl;
cvNamedWindow( "result", 1 );
if( capture )
{
cout << "In capture ..." << endl;
for(;;)
{
IplImage* iplImg = cvQueryFrame( capture );
frame = iplImg;
if( frame.empty() )
break;
if( iplImg->origin == IPL_ORIGIN_TL )
frame.copyTo( frameCopy );
else
flip( frame, frameCopy, 0 );
cvShowImage( "result", iplImg );
if( waitKey( 10 ) >= 0 )
cvReleaseCapture( &capture );
}
waitKey(0);
cvDestroyWindow("result");
return 0;
}
return 0;
}
#else
{
// opencv 2 style
VideoCapture cap(0);
if(!cap.isOpened())
{
cout << "No camera detected" << endl;
return -1;
}
else
{
cout << "In capture ..." << endl;
}
namedWindow( "Display window", WINDOW_AUTOSIZE );
for(;;)
{
Mat frame;
if(!cap.read(frame)) break;
imshow("Display window", frame);
if(waitKey(30) >= 0) break;
}
return 0;
}
#endif |