dimanche 27 avril 2014

c ++ - image unique de Capture de webcam - Stack Overflow


What would be the best way using the best library to quickly capture a single image from a webcam with c++? EDIT:
Although the faq example showed how to capture a stream of frames, I morphed it a little to do what I need. Thank you.


include "cv.h"  
include "highgui.h"
include stdio.h>
int main() {
CvCapture* capture = cvCaptureFromCAM(CV_CAP_ANY);
if(!capture){
fprintf(stderr, "ERROR: capture is NULL \n");
getchar();
return -1;
}
cvNamedWindow("mywindow", CV_WINDOW_AUTOSIZE);
IplImage* frame = cvQueryFrame(capture);
if(!frame){
fprintf(stderr,"ERROR: frame is null.. \n");
getchar();
}
while(1){
cvShowImage("mywindow", frame);
if((cvWaitKey(10) & 255) == 27) break;
}
cvReleaseCapture(&capture);
cvDestroyWindow("mywindow");
return 0;
}



OpenCV has C and C++ APIs, is cross-platform, and is very easy to use. There is an example in Learning OpenCV on page 26-27 which covers capturing a single frame from a webcam. There is also an example in the OpenCV FAQ: http://opencv.willowgarage.com/wiki/CameraCapture



What would be the best way using the best library to quickly capture a single image from a webcam with c++? EDIT:
Although the faq example showed how to capture a stream of frames, I morphed it a little to do what I need. Thank you.


include "cv.h"  
include "highgui.h"
include stdio.h>
int main() {
CvCapture* capture = cvCaptureFromCAM(CV_CAP_ANY);
if(!capture){
fprintf(stderr, "ERROR: capture is NULL \n");
getchar();
return -1;
}
cvNamedWindow("mywindow", CV_WINDOW_AUTOSIZE);
IplImage* frame = cvQueryFrame(capture);
if(!frame){
fprintf(stderr,"ERROR: frame is null.. \n");
getchar();
}
while(1){
cvShowImage("mywindow", frame);
if((cvWaitKey(10) & 255) == 27) break;
}
cvReleaseCapture(&capture);
cvDestroyWindow("mywindow");
return 0;
}


OpenCV has C and C++ APIs, is cross-platform, and is very easy to use. There is an example in Learning OpenCV on page 26-27 which covers capturing a single frame from a webcam. There is also an example in the OpenCV FAQ: http://opencv.willowgarage.com/wiki/CameraCapture


Related Posts:

0 commentaires:

Enregistrer un commentaire