Example of framegrabbing using OpenCV cv::VideoCapture class.
#include <visp/vpConfig.h>
#include <iostream>
#include <visp/vpConfig.h>
#if defined(VISP_HAVE_OPENCV)
#include <visp/vpDisplayOpenCV.h>
#include <visp/vpImage.h>
#include <visp/vpImageConvert.h>
#include <visp/vpOpenCVGrabber.h>
int main(int argc, char** argv)
{
try {
int device = 0;
if (argc > 1)
device = atoi(argv[1]);
std::cout << "Use device: " << device << std::endl;
cv::VideoCapture cap(device);
cap.set(CV_CAP_PROP_FRAME_WIDTH, 640);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, 480);
if(!cap.isOpened())
return -1;
cv::Mat frame;
cap >> frame;
IplImage iplimage = frame;
std::cout << "Image size: " << iplimage.width << " "
<< iplimage.height << std::endl;
for(;;) {
cap >> frame;
iplimage = frame;
break;
}
return 0;
}
std::cout << "Catch an exception: " << e << std::endl;
return 1;
}
}
#else
int main()
{
std::cout << "OpenCV is not available..." << std::endl;
}
#endif