Example of framegrabbing using OpenCV cv::VideoCapture class.
#include <visp3/core/vpConfig.h>
#include <iostream>
#include <visp3/core/vpConfig.h>
#if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100)
#include <visp3/core/vpImage.h>
#include <visp3/core/vpImageConvert.h>
#include <visp3/gui/vpDisplayOpenCV.h>
#include <visp3/sensor/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);
#if (VISP_HAVE_OPENCV_VERSION >= 0x030000)
cap.set(cv::CAP_PROP_FRAME_WIDTH, 640);
cap.set(cv::CAP_PROP_FRAME_HEIGHT, 480);
#else
cap.set(CV_CAP_PROP_FRAME_WIDTH, 640);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, 480);
#endif
if (!cap.isOpened())
return -1;
cv::Mat frame;
int i = 0;
while ((i++ < 100) && !cap.read(frame)) {
};
std::cout << "Image size: "
#if (VISP_HAVE_OPENCV_VERSION >= 0x030000)
<< (int)cap.get(cv::CAP_PROP_FRAME_WIDTH) << " " << (int)cap.get(cv::CAP_PROP_FRAME_HEIGHT) << std::endl;
#else
<< (int)cap.get(CV_CAP_PROP_FRAME_WIDTH) << " " << (int)cap.get(CV_CAP_PROP_FRAME_HEIGHT) << std::endl;
#endif
for (;;) {
cap >> 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