forked from lagadic/visp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tutorial-grabber.doc
145 lines (92 loc) · 7.08 KB
/
tutorial-grabber.doc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
\page tutorial-grabber Tutorial: Image frame grabbing
\tableofcontents
\section grabber-camera-pgr Images from PointGrey cameras
After ViSP 3.0.0, we introduce vpFlyCaptureGrabber class, a wrapper over PointGrey FlyCapture SDK that allows to grab images from any PointGrey camera. This grabber was tested under Ubuntu and Windows with the following cameras:
- Flea3 USB 3.0 cameras (FL3-U3-32S2M-CS, FL3-U3-13E4C-C)
- Flea2 firewire camera (FL2-03S2C)
- Dragonfly2 firewire camera (DR2-COL)
It should also work with GigE PGR cameras.
The following example also available in tutorial-grabber-flycapture.cpp shows how to use vpFlyCaptureGrabber to capture grey level images from a PointGrey camera under Ubuntu or Windows. The following example suppose that a window renderer (libX11 on Ubuntu or GDI on Windows) and FlyCapture SDK 3rd party are available throw VISP.
\include tutorial-grabber-flycapture.cpp
Here after we explain the source code.
First an instance of the frame grabber is created.
\snippet tutorial-grabber-flycapture.cpp vpFlyCaptureGrabber construction
Once the grabber is created, we turn auto shutter and auto gain on and set the camera image size, color coding, and framerate.
These settings are enclosed in a try/catch to be able to continue if one of these settings are not supported by the camera.
\snippet tutorial-grabber-flycapture.cpp vpFlyCaptureGrabber settings
Then the grabber is initialized using:
\snippet tutorial-grabber-flycapture.cpp vpFlyCaptureGrabber open
From now the grey level image \c I is also initialized with the size corresponding to the grabber settings.
Then we enter in a while loop where image acquisition is simply done by:
\snippet tutorial-grabber-flycapture.cpp vpFlyCaptureGrabber acquire
This image is then displayed using libX11 or GDI renderer:
\snippet tutorial-grabber-flycapture.cpp vpFlyCaptureGrabber display
We are waiting for a non blocking mouse event to break the while loop before ending the program.
\snippet tutorial-grabber-flycapture.cpp vpFlyCaptureGrabber click to exit
\section grabber-camera-firewire-unix Images from firewire cameras
The next example also available in tutorial-grabber-1394.cpp shows how to use a framegrabber to acquire color images from a firewire camera under Unix. The following example suppose that libX11 and libdc1394-2 3rd party are available.
\include tutorial-grabber-1394.cpp
Here after we explain the new lines that are introduced.
First an instance of the frame grabber is created. During the creating a bus reset is send. If you don't want to reset the firewire bus, just turn reset to false.
\snippet tutorial-grabber-1394.cpp vp1394TwoGrabber construction
Once the grabber is created, we set the camera image size, color coding, and framerate.
\snippet tutorial-grabber-1394.cpp vp1394TwoGrabber settings
Note that here you can specify some other settings such as the firewire transmission speed. For a more complete list of settings see vp1394TwoGrabber class.
\code
g.setIsoTransmissionSpeed(vp1394TwoGrabber::vpISO_SPEED_800);
\endcode
Then the grabber is initialized using:
\snippet tutorial-grabber-1394.cpp vp1394TwoGrabber open
From now the color image \c I is also initialized with the size corresponding to the grabber settings.
Then we enter in a while loop where image acquisition is simply done by:
\snippet tutorial-grabber-1394.cpp vp1394TwoGrabber acquire
We are waiting for a non blocking mouse event to break the while loop before ending the program.
\snippet tutorial-grabber-1394.cpp vp1394TwoGrabber click to exit
In the previous example we use vp1394TwoGrabber class that works for firewire cameras under Unix. If you are under Windows, you may use vp1394CMUGrabber class. A similar example is provided in tutorial-grabber-CMU1394.cpp.
\section grabber-camera-other Images from other cameras
If you want to grab images from an usb camera under Unix, you may use vpV4l2Grabber class. To this end libv4l should be installed. An example is provided in tutorial-grabber-v4l2.cpp.
It is also possible to grab images using OpenCV. You may find an example in tutorial-grabber-opencv.cpp.
\section grabber-video-stream Images from a video stream
With ViSP it also possible to get images from an input video stream. Supported formats are *.avi, *.mp4, *.mov, *.ogv, *.flv and many others... To this end we exploit ffmpeg or OpenCV 3rd parties.
If ViSP was build with ffmpeg 3rd party support (cmake -DUSE_FFMPEG=ON ...), we use ffmpeg capabilities to decode the video stream. If ffmpeg is not found or used (cmake -DUSE_FFMPEG=OFF ...) and if OpenCV is available (cmake -DUSE_OPENCV=ON ...) we use rather OpenCV capabilities. This new feature was introduced in ViSP 2.10.0 and is especially useful under Windows where installing ffmpeg is quite complex.
The example below available in tutorial-video-reader.cpp shows how o consider an mpeg video stream.
\warning We recall that this example works only if ViSP was build with ffmpeg or OpenCV support.
\include tutorial-video-reader.cpp
We explain now the new lines that were introduced.
\snippet tutorial-video-reader.cpp Include
Include the header of the vpTime class that allows to measure time, and of the vpVideoReader class that allows to read a video stream.
\snippet tutorial-video-reader.cpp vpVideoReader construction
Create an instance of a video reader.
\snippet tutorial-video-reader.cpp vpVideoReader setting
Set the name of the video stream. Here \c videoname corresponds to a video file name location. For example we provide the file \c video.mpg located in the same folder than the executable.
The vpVideoReader class can also handle a sequence of images. For example, to read the following images:
\code
% ls *.png
image0000.png
image0001.png
image0002.png
image0003.png
image0004.png
...
\endcode
you may use the following:
\code
g.setFileName("./image%04d.png");
\endcode
where you specify that each image number is coded with 4 digits. Here, ffmpeg is no yet mandatory, but rather \c libpng or OpenCV that should be available to read PNG images. Supported image formats are PPM, PGM, PNG and JPEG.
Then as for any other grabber, you have to initialize the frame grabber using:
\snippet tutorial-video-reader.cpp vpVideoReader open
Then we enter in the while loop until the last image was not reached:
\snippet tutorial-video-reader.cpp vpVideoReader while loop
To get the next image in the stream, we just use:
\snippet tutorial-video-reader.cpp vpVideoReader acquire
To synchronize the video decoding with the video framerate, we measure the beginning time of each loop iteration:
\snippet tutorial-video-reader.cpp vpVideoReader loop start time
The synchronization is done by waiting from the beginning of the iteration the corresponding time expressed in milliseconds by using:
\snippet tutorial-video-reader.cpp vpVideoReader loop rate
\section grabber-next Next tutorial
You are now ready to see how to continue with:
- \ref tutorial-multi-threading if you want to see how to extend these examples with one thread for capture and an other one for display
- or with a simple image processing that shows how to track blobs explained in \ref tutorial-tracking-blob.
*/