Visual Servoing Platform  version 3.0.0
tutorial-grabber-opencv-bis.cpp
1 
2 #include <stdlib.h>
3 #include <visp3/gui/vpDisplayOpenCV.h>
4 #include <visp3/core/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 (VISP_HAVE_OPENCV_VERSION >= 0x020100)
17  try {
18  cv::VideoCapture cap(device); // open the default camera
19  if(!cap.isOpened()) { // check if we succeeded
20  std::cout << "Failed to open the camera" << std::endl;
21  return -1;
22  }
23  cv::Mat frame;
24  cap >> frame; // get a new frame from camera
25  std::cout << "Image size: " << frame.rows << " " << frame.cols << std::endl;
26 
27  //vpImage<vpRGBa> I; // for color images
28  vpImage<unsigned char> I; // for gray images
29  vpImageConvert::convert(frame, I);
30 
31  vpDisplayOpenCV d(I);
32 
33  for(;;) {
34  cap >> frame; // get a new frame from camera
35  // Convert the image in ViSP format and display it
36  vpImageConvert::convert(frame, I);
39  if (vpDisplay::getClick(I, false)) // a click to exit
40  break;
41  }
42  }
43  catch(vpException e) {
44  std::cout << "Catch an exception: " << e << std::endl;
45  }
46 #endif
47 }
48 
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
error that can be emited by ViSP classes.
Definition: vpException.h:73
static void flush(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:2233
static void display(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:206
The vpDisplayOpenCV allows to display image using the opencv library.
virtual bool getClick(bool blocking=true)=0