Created
February 18, 2016 22:16
-
-
Save akihikoy/38825f339dbf24abf77c to your computer and use it in GitHub Desktop.
A simple example of OpenCV... Just capture images from a USB camera, and display it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <opencv2/core/core.hpp> | |
#include <opencv2/highgui/highgui.hpp> | |
#include <iostream> | |
#include <cstdio> | |
int main(int argc, char **argv) | |
{ | |
cv::VideoCapture cap(0); // open the default camera | |
if(argc==2) | |
{ | |
cap.release(); | |
cap.open(atoi(argv[1])); | |
} | |
if(!cap.isOpened()) // check if we succeeded | |
{ | |
std::cerr<<"no camera!"<<std::endl; | |
return -1; | |
} | |
std::cerr<<"camera opened"<<std::endl; | |
cv::namedWindow("camera",1); | |
cv::Mat frame; | |
for(;;) | |
{ | |
cap >> frame; // get a new frame from camera | |
cv::imshow("camera", frame); | |
int c(cv::waitKey(10)); | |
if(c=='\x1b'||c=='q') break; | |
// usleep(10000); | |
} | |
// the camera will be deinitialized automatically in VideoCapture destructor | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment