ViSP  2.8.0
tutorial-grabber-opencv-bis.cpp
1 
2 #include <stdlib.h>
3 #include <visp/vpDisplayOpenCV.h>
4 #include <visp/vpImageConvert.h>
5 
6 // usage: binary <device name>
7 // device name: 0 is the default to dial with the first camera,
8 // 1 to dial with a second camera attached to the computer
9 int main(int argc, char** argv)
10 {
11  int device = 0;
12  if (argc > 1)
13  device = atoi(argv[1]);
14  std::cout << "Use device: " << device << std::endl;
15 
16 #if defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100)
17  cv::VideoCapture cap(device); // open the default camera
18  if(!cap.isOpened()) { // check if we succeeded
19  std::cout << "Failed to open the camera" << std::endl;
20  return -1;
21  }
22  cv::Mat frame;
23  cap >> frame; // get a new frame from camera
24  std::cout << "Image size: " << frame.rows << " " << frame.cols << std::endl;
25 
26  //vpImage<vpRGBa> I; // for color images
27  vpImage<unsigned char> I; // for gray images
28  vpImageConvert::convert(frame, I);
29  vpDisplayOpenCV d(I);
30  for(;;) {
31  cap >> frame; // get a new frame from camera
32  // Convert the image in ViSP format and display it
33  vpImageConvert::convert(frame, I);
36  if (vpDisplay::getClick(I, false)) // a click to exit
37  break;
38  }
39 #endif
40 }
41 
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
static void flush(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:1991
static void display(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:203
The vpDisplayOpenCV allows to display image using the opencv library.
virtual bool getClick(bool blocking=true)=0