//this code also works
#include <opencv2/core.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <stdio.h>
using namespace cv;
using namespace std;
int main(int, char**)
{
Mat frame;
//--- INITIALIZE VIDEOCAPTURE
VideoCapture cap;
// open the default camera using default API
// cap.open(0);
// OR advance usage: select any API backend
int deviceID = 0; // 0 = open default camera
int apiID = cv::CAP_ANY; // 0 = autodetect default API
// open selected camera using selected API
cap.open(deviceID, apiID);
// check if we succeeded
if (!cap.isOpened()) {
cerr << "ERROR! Unable to open camera
";
return -1;
}
//--- GRAB AND WRITE LOOP
cout << "Start grabbing" << endl
<< "Press any key to terminate" << endl;
for (;;)
{
// wait for a new frame from camera and store it into 'frame'
cap.read(frame);
// check if we succeeded
if (frame.empty()) {
cerr << "ERROR! blank frame grabbed
";
break;
}
// show live and wait for a key with timeout long enough to show images
imshow("Live", frame);
if (waitKey(5) >= 0)
break;
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}
Code Example |
---|
Cpp :: strcmp in c++ header file |
Cpp :: c++ throe |
Cpp :: stricmp CPP |
Cpp :: c program runner |
Cpp :: apertura file in c++ |
Cpp :: convert string to double arduino |
Cpp :: Summation of Natural Number Sequence with c and c++. |
Cpp :: mpi wait |
Cpp :: std::is_standard_layout |
Cpp :: int and char in c++ compiler |
Cpp :: c++ text between substrings |
Cpp :: sort vector in descending order c++ |
Cpp :: codeforces problem 1700A solution in c++ |
Cpp :: dinamic |
Cpp :: how to open program in c++ |
Cpp :: c++ click event |
Cpp :: tan trigonometric function |
Cpp :: delay without blocking |
Cpp :: beecrowd problem 1003 solution in c++ |
Cpp :: C++ selectin file location using Win32 API |
Cpp :: For auto map C |
Cpp :: how to refresh multiple command lines in C++ stream |
Cpp :: do c++ ints neeed to be initlaized |
Cpp :: c+ |
Cpp :: c++ create a vecto |
Cpp :: Character convert c++ |
Cpp :: convert "c++ to c" code online |
Cpp :: set app icon qt |
Cpp :: 123213 |
Cpp :: C++ Point to Every Array Elements |