Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
vpV4l2Grabber.h
1
/*
2
* ViSP, open source Visual Servoing Platform software.
3
* Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4
*
5
* This software is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
9
* See the file LICENSE.txt at the root directory of this source
10
* distribution for additional information about the GNU GPL.
11
*
12
* For using ViSP with software that can not be combined with the GNU
13
* GPL, please contact Inria about acquiring a ViSP Professional
14
* Edition License.
15
*
16
* See https://visp.inria.fr for more information.
17
*
18
* This software was developed at:
19
* Inria Rennes - Bretagne Atlantique
20
* Campus Universitaire de Beaulieu
21
* 35042 Rennes Cedex
22
* France
23
*
24
* If you have questions regarding the use of this file, please contact
25
* Inria at visp@inria.fr
26
*
27
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29
*
30
* Description:
31
* Video for linux two framegrabber.
32
*/
33
38
39
#ifndef vpV4l2Grabber_hh
40
#define vpV4l2Grabber_hh
41
42
#include <visp3/core/vpConfig.h>
43
44
#ifdef VISP_HAVE_V4L2
45
46
#include <libv4l2.h>
// Video For Linux Two interface
47
#include <linux/videodev2.h>
// Video For Linux Two interface
48
#include <string>
49
50
#include <visp3/core/vpFrameGrabber.h>
51
#include <visp3/core/vpImage.h>
52
#include <visp3/core/vpRGBa.h>
53
#include <visp3/core/vpRect.h>
54
55
BEGIN_VISP_NAMESPACE
129
class
VISP_EXPORT
vpV4l2Grabber
:
public
vpFrameGrabber
130
{
131
public
:
132
static
const
unsigned
int
DEFAULT_INPUT
;
133
static
const
unsigned
int
DEFAULT_SCALE
;
134
static
const
__u32
MAX_INPUTS
;
135
static
const
__u32
MAX_NORM
;
136
static
const
__u32
MAX_FORMAT
;
137
static
const
unsigned
int
MAX_CTRL
;
138
static
const
unsigned
int
MAX_BUFFERS
;
139
static
const
unsigned
int
FRAME_SIZE
;
140
144
typedef
enum
145
{
146
framerate_50fps
,
147
framerate_25fps
148
} vpV4l2FramerateType;
149
153
typedef
enum
154
{
155
V4L2_FRAME_FORMAT
,
156
V4L2_IMAGE_FORMAT
157
} vpV4l2FrameFormatType;
158
162
typedef
enum
163
{
164
V4L2_GREY_FORMAT
,
165
V4L2_RGB24_FORMAT
,
166
V4L2_RGB32_FORMAT
,
167
V4L2_BGR24_FORMAT
,
168
V4L2_YUYV_FORMAT
,
169
V4L2_MAX_FORMAT
170
} vpV4l2PixelFormatType;
171
172
#ifndef DOXYGEN_SHOULD_SKIP_THIS
173
struct
ng_video_fmt
174
{
175
unsigned
int
pixelformat;
/* VIDEO_* */
176
unsigned
int
width;
177
unsigned
int
height;
178
unsigned
int
bytesperline;
/* zero for compressed formats */
179
};
180
181
struct
ng_video_buf
182
{
183
struct
ng_video_fmt fmt;
184
size_t
size;
185
unsigned
char
*
data
;
186
int
refcount;
187
};
188
#endif
189
190
// private:
191
//#ifndef DOXYGEN_SHOULD_SKIP_THIS
192
// vpV4l2Grabber(const vpV4l2Grabber &)
193
// : fd(-1), device(), cap(), streamparm(), inp(nullptr), std(nullptr),
194
// fmt(nullptr), ctl(nullptr),
195
// fmt_v4l2(), fmt_me(), reqbufs(), buf_v4l2(nullptr), buf_me(nullptr),
196
// queue(0), waiton_cpt(0), index_buffer(0), m_verbose(false),
197
// m_nbuffers(3), field(0), streaming(false),
198
// m_input(vpV4l2Grabber::DEFAULT_INPUT),
199
// m_framerate(vpV4l2Grabber::framerate_25fps),
200
// m_frameformat(vpV4l2Grabber::V4L2_FRAME_FORMAT),
201
// m_pixelformat(vpV4l2Grabber::V4L2_YUYV_FORMAT)
202
// {
203
// throw vpException(vpException::functionNotImplementedError,"Not
204
// implemented!");
205
// }
206
// vpV4l2Grabber &operator=(const vpV4l2Grabber &){
207
// throw vpException(vpException::functionNotImplementedError,"Not
208
// implemented!"); return *this;
209
// }
210
//#endif
211
212
#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
213
vpV4l2Grabber
(
const
vpV4l2Grabber
&) =
delete
;
// non construction-copyable
214
vpV4l2Grabber
&
operator=
(
const
vpV4l2Grabber
&) =
delete
;
// non copyable
215
#endif
216
217
public
:
218
vpV4l2Grabber
();
219
VP_EXPLICIT
vpV4l2Grabber
(
bool
verbose);
220
vpV4l2Grabber
(
unsigned
input,
unsigned
scale =
vpV4l2Grabber::DEFAULT_SCALE
);
221
vpV4l2Grabber
(
vpImage<unsigned char>
&I,
unsigned
input,
unsigned
scale =
vpV4l2Grabber::DEFAULT_SCALE
);
222
vpV4l2Grabber
(
vpImage<vpRGBa>
&I,
unsigned
input,
unsigned
scale =
vpV4l2Grabber::DEFAULT_SCALE
);
223
virtual
~vpV4l2Grabber
();
224
225
public
:
226
void
open
(
vpImage<unsigned char>
&I);
227
void
open
(
vpImage<vpRGBa>
&I);
228
229
void
acquire
(
vpImage<unsigned char>
&I);
230
void
acquire
(
vpImage<unsigned char>
&I,
const
vpRect
&roi);
231
void
acquire
(
vpImage<unsigned char>
&I,
struct
timeval ×tamp,
const
vpRect
&roi =
vpRect
());
232
void
acquire
(
vpImage<vpRGBa>
&I);
233
void
acquire
(
vpImage<vpRGBa>
&I,
const
vpRect
&roi);
234
void
acquire
(
vpImage<vpRGBa>
&I,
struct
timeval ×tamp,
const
vpRect
&roi =
vpRect
());
235
bool
getField
();
236
vpV4l2FramerateType
getFramerate
();
244
inline
vpV4l2PixelFormatType
getPixelFormat
() {
return
(this->m_pixelformat); }
245
246
vpV4l2Grabber
&operator>>(
vpImage<unsigned char>
&I);
247
vpV4l2Grabber
&operator>>(
vpImage<vpRGBa>
&I);
248
253
void
setVerboseMode
(
bool
verbose) { this->m_verbose = verbose; }
254
void
setFramerate(vpV4l2FramerateType framerate);
255
256
void
setInput(
unsigned
input =
vpV4l2Grabber::DEFAULT_INPUT
);
257
262
inline
void
setWidth
(
unsigned
w) { this->
width
= w; }
267
inline
void
setHeight
(
unsigned
h) { this->
height
= h; }
268
269
void
setScale(
unsigned
scale =
vpV4l2Grabber::DEFAULT_SCALE
);
270
282
inline
void
setNBuffers
(
unsigned
nbuffers) { this->m_nbuffers = nbuffers; }
283
290
inline
void
setDevice
(
const
std::string &devname) { device = devname; }
299
inline
void
setPixelFormat
(
vpV4l2PixelFormatType
pixelformat)
300
{
301
this->m_pixelformat = pixelformat;
302
if
(this->m_pixelformat >=
V4L2_MAX_FORMAT
)
303
this->m_pixelformat =
V4L2_RGB24_FORMAT
;
304
}
305
306
void
close
();
307
308
private
:
309
void
setFormat();
317
inline
void
setFrameFormat(vpV4l2FrameFormatType frameformat) { this->m_frameformat = frameformat; }
318
void
open
();
319
void
getCapabilities();
320
void
startStreaming();
321
void
stopStreaming();
322
unsigned
char
*waiton(__u32 &index,
struct
timeval ×tamp);
323
int
queueBuffer();
324
void
queueAll();
325
void
printBufInfo(
struct
v4l2_buffer buf);
326
327
int
fd;
328
std::string device;
329
/* device descriptions */
330
struct
v4l2_capability cap;
331
struct
v4l2_streamparm streamparm;
332
struct
v4l2_input *inp;
//[vpV4l2Grabber::MAX_INPUTS];
333
struct
v4l2_standard *std;
//[vpV4l2Grabber::MAX_NORM];
334
struct
v4l2_fmtdesc *fmt;
//[vpV4l2Grabber::MAX_FORMAT];
335
struct
v4l2_queryctrl *ctl;
//[vpV4l2Grabber::MAX_CTRL*2];
336
337
/* capture */
338
struct
v4l2_format fmt_v4l2;
339
struct
ng_video_fmt fmt_me;
340
struct
v4l2_requestbuffers reqbufs;
341
struct
v4l2_buffer *buf_v4l2;
//[vpV4l2Grabber::MAX_BUFFERS];
342
struct
ng_video_buf *buf_me;
//[vpV4l2Grabber::MAX_BUFFERS];
343
unsigned
int
queue;
344
unsigned
int
waiton_cpt;
345
__u32 index_buffer;
346
347
bool
m_verbose;
348
unsigned
m_nbuffers;
349
unsigned
int
field;
350
bool
streaming;
351
352
unsigned
m_input;
353
vpV4l2FramerateType m_framerate;
354
vpV4l2FrameFormatType m_frameformat;
355
vpV4l2PixelFormatType m_pixelformat;
356
};
357
END_VISP_NAMESPACE
358
#endif
359
#endif
vpFrameGrabber::open
virtual void open(vpImage< unsigned char > &I)=0
vpFrameGrabber::height
unsigned int height
Number of rows in the image.
Definition
vpFrameGrabber.h:139
vpFrameGrabber::width
unsigned int width
Number of columns in the image.
Definition
vpFrameGrabber.h:140
vpFrameGrabber::vpFrameGrabber
vpFrameGrabber()
Definition
vpFrameGrabber.h:114
vpFrameGrabber::acquire
virtual void acquire(vpImage< unsigned char > &I)=0
vpFrameGrabber::close
virtual void close()=0
vpImage
Definition of the vpImage class member functions.
Definition
vpImage.h:131
vpRect
Defines a rectangle in the plane.
Definition
vpRect.h:79
vpV4l2Grabber
Class that is a wrapper over the Video4Linux2 (V4L2) driver.
Definition
vpV4l2Grabber.h:130
vpV4l2Grabber::vpV4l2FramerateType
vpV4l2FramerateType
Definition
vpV4l2Grabber.h:145
vpV4l2Grabber::framerate_50fps
@ framerate_50fps
50 frames per second
Definition
vpV4l2Grabber.h:146
vpV4l2Grabber::framerate_25fps
@ framerate_25fps
25 frames per second
Definition
vpV4l2Grabber.h:147
vpV4l2Grabber::setWidth
void setWidth(unsigned w)
Definition
vpV4l2Grabber.h:262
vpV4l2Grabber::MAX_NORM
static const __u32 MAX_NORM
Definition
vpV4l2Grabber.h:135
vpV4l2Grabber::vpV4l2PixelFormatType
vpV4l2PixelFormatType
Definition
vpV4l2Grabber.h:163
vpV4l2Grabber::V4L2_BGR24_FORMAT
@ V4L2_BGR24_FORMAT
Definition
vpV4l2Grabber.h:167
vpV4l2Grabber::V4L2_GREY_FORMAT
@ V4L2_GREY_FORMAT
Definition
vpV4l2Grabber.h:164
vpV4l2Grabber::V4L2_YUYV_FORMAT
@ V4L2_YUYV_FORMAT
Definition
vpV4l2Grabber.h:168
vpV4l2Grabber::V4L2_RGB24_FORMAT
@ V4L2_RGB24_FORMAT
Definition
vpV4l2Grabber.h:165
vpV4l2Grabber::V4L2_MAX_FORMAT
@ V4L2_MAX_FORMAT
Definition
vpV4l2Grabber.h:169
vpV4l2Grabber::V4L2_RGB32_FORMAT
@ V4L2_RGB32_FORMAT
Definition
vpV4l2Grabber.h:166
vpV4l2Grabber::V4L2_FRAME_FORMAT
@ V4L2_FRAME_FORMAT
Definition
vpV4l2Grabber.h:155
vpV4l2Grabber::V4L2_IMAGE_FORMAT
@ V4L2_IMAGE_FORMAT
Definition
vpV4l2Grabber.h:156
vpV4l2Grabber::MAX_CTRL
static const unsigned int MAX_CTRL
Definition
vpV4l2Grabber.h:137
vpV4l2Grabber::MAX_BUFFERS
static const unsigned int MAX_BUFFERS
Definition
vpV4l2Grabber.h:138
vpV4l2Grabber::operator=
vpV4l2Grabber & operator=(const vpV4l2Grabber &)=delete
vpV4l2Grabber::MAX_INPUTS
static const __u32 MAX_INPUTS
Definition
vpV4l2Grabber.h:134
vpV4l2Grabber::DEFAULT_INPUT
static const unsigned int DEFAULT_INPUT
Definition
vpV4l2Grabber.h:132
vpV4l2Grabber::setVerboseMode
void setVerboseMode(bool verbose)
Definition
vpV4l2Grabber.h:253
vpV4l2Grabber::vpV4l2Grabber
vpV4l2Grabber(const vpV4l2Grabber &)=delete
vpV4l2Grabber::getPixelFormat
vpV4l2PixelFormatType getPixelFormat()
Definition
vpV4l2Grabber.h:244
vpV4l2Grabber::FRAME_SIZE
static const unsigned int FRAME_SIZE
Definition
vpV4l2Grabber.h:139
vpV4l2Grabber::getField
bool getField()
Definition
vpV4l2Grabber.cpp:793
vpV4l2Grabber::DEFAULT_SCALE
static const unsigned int DEFAULT_SCALE
Definition
vpV4l2Grabber.h:133
vpV4l2Grabber::MAX_FORMAT
static const __u32 MAX_FORMAT
Definition
vpV4l2Grabber.h:136
vpV4l2Grabber::setHeight
void setHeight(unsigned h)
Definition
vpV4l2Grabber.h:267
vpV4l2Grabber::setPixelFormat
void setPixelFormat(vpV4l2PixelFormatType pixelformat)
Definition
vpV4l2Grabber.h:299
vpV4l2Grabber::setNBuffers
void setNBuffers(unsigned nbuffers)
Definition
vpV4l2Grabber.h:282
vpV4l2Grabber::getFramerate
vpV4l2FramerateType getFramerate()
Definition
vpV4l2Grabber.cpp:839
vpV4l2Grabber::setDevice
void setDevice(const std::string &devname)
Definition
vpV4l2Grabber.h:290
BEGIN_VISP_NAMESPACE
Definition
vpMbtDistanceCircle.cpp:55
test-serial-read.data
data
Definition
test-serial-read.py:18
modules
sensor
include
visp3
sensor
vpV4l2Grabber.h
Generated by
1.17.0