ViSP
Main Page
Related Pages
Modules
Classes
Examples
All
Classes
Functions
Variables
Enumerations
Enumerator
Friends
Groups
Pages
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);
34
vpDisplay::display
(I);
35
vpDisplay::flush
(I);
36
if
(
vpDisplay::getClick
(I,
false
))
// a click to exit
37
break
;
38
}
39
#endif
40
}
41
tutorial
grabber
tutorial-grabber-opencv-bis.cpp
Generated on Thu Nov 7 2013 03:14:09 for ViSP by
1.8.4