Last active
December 24, 2015 13:19
-
-
Save itolosa/830b42bc3423d8d6d497 to your computer and use it in GitHub Desktop.
Test for camera using OpenCV in OS X
This file contains hidden or 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 <iostream> | |
#include <highgui.h> | |
#include <opencv2/imgproc/imgproc.hpp> | |
using namespace std; | |
#define CAMERA_OUTPUT_WINDOW_NAME "camera-output" | |
int main(int argc, char **argv) | |
{ | |
CvCapture *camCapture; | |
int ret = 0; | |
if (!(camCapture = cvCaptureFromCAM(CV_CAP_ANY))) { | |
cout << "Failed to capture from camera" << endl; | |
ret = 1; | |
goto exitCameraOpenFailed; | |
} | |
cout << "Camera opened successfully" << endl; | |
cvNamedWindow(CAMERA_OUTPUT_WINDOW_NAME, CV_WINDOW_AUTOSIZE); | |
IplImage *cameraFrame; | |
int grabFrameRet; | |
while (true) { | |
if ((cameraFrame = cvQueryFrame(camCapture))) { | |
cvShowImage(CAMERA_OUTPUT_WINDOW_NAME, cameraFrame); | |
} | |
if (cvWaitKey(60) != -1) { | |
cout << "Input" << endl; | |
break; | |
} | |
} | |
cout << "Done" << endl; | |
cvReleaseCapture(&camCapture); | |
cvDestroyWindow(CAMERA_OUTPUT_WINDOW_NAME); | |
exitCameraOpenFailed: | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment