JeVois  1.20
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
VideoInput.H
Go to the documentation of this file.
1 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 //
3 // JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2016 by Laurent Itti, the University of Southern
4 // California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
5 //
6 // This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
7 // redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
8 // Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
10 // License for more details. You should have received a copy of the GNU General Public License along with this program;
11 // if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12 //
13 // Contact information: Laurent Itti - 3641 Watt Way, HNB-07A - Los Angeles, CA 90089-2520 - USA.
14 // Tel: +1 213 740 3527 - itti@pollux.usc.edu - http://iLab.usc.edu - http://jevois.org
15 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16 /*! \file */
17 
18 #pragma once
19 
20 #include <jevois/Image/RawImage.H>
22 
23 namespace jevois
24 {
25  //! Base class for video input, which will get derived into Camera and MovieInput
26  /*! Engine uses a VideoInput to capture input frames and pass them to its currently loaded machine vision Module for
27  processing. The VideoInput class is abstract and simply defines the interface. For live video processing, Engine
28  will implement its VideoInput as a Camera, and for processing of pre-recorded videos or image sequences (useful to
29  debug or tune an algorithm on reproducible image sequences), it can also implement its VideoInout as a
30  MovieInput. \ingroup core */
31  class VideoInput
32  {
33  public:
34  //! Constructor
35  /*! \param devname name of the device, or movie file, or empty
36  \param nbufs number of video buffers to use, or 0 for automatic. */
37  VideoInput(std::string const & devname, unsigned int const nbufs = 0);
38 
39  //! Virtual destructor for save inheritance
40  virtual ~VideoInput();
41 
42  //! Start streaming
43  virtual void streamOn() = 0;
44 
45  //! Abort streaming
46  /*! This only cancels future get() and done() calls, one should still call streamOff() to turn off streaming. */
47  virtual void abortStream() = 0;
48 
49  //! Stop streaming
50  virtual void streamOff() = 0;
51 
52  //! Get the next captured buffer
53  /*! Throws if we are not streaming or blocks until an image is available (has been captured). The image img should
54  have been allocated by the caller and will be filled in by what we receive from the device here. */
55  virtual void get(RawImage & img) = 0;
56 
57  //! Check whether a second input image scaled by the JeVoisPro Platform ISP is available
58  /*! Returns false unless we are on JeVois-Pro Platform and the camera format modifier jevois::CropType::CropScale
59  is currently in use. */
60  virtual bool hasScaledImage() const;
61 
62  //! Get the next captured ISP-scaled secondary buffer
63  /*! On JeVois-Pro Platform only, the camera ISP can output 2 frames: 1) raw from sensor, 2) scaled by ISP. This
64  function is to access the ISP scaled frame. Throws if not JeVois-Pro Platform or the camera crop type is not
65  jevois::CropType::CropScale. Throws if we are not streaming or blocks until an image is available (has
66  been captured). The image img should have been allocated by the caller and will be filled in by what we
67  receive from the device here. Default implementation throws. */
68  virtual void get2(RawImage & img);
69 
70  //! Indicate that user processing is done with an image previously obtained via get()
71  /*! You should call this as soon after get() as possible, once you are finished with the RawImage data so that it
72  can be recycled.
73 
74  \note This also invalidates the image and in particular its pixel buffer! */
75  virtual void done(RawImage & img) = 0;
76 
77  //! Indicate that user processing is done with a second ISP-scaled image previously obtained via get2()
78  /*! You should call this as soon after get2() as possible, once you are finished with the RawImage data so that it
79  can be recycled. Default implementation throws.
80 
81  \note This also invalidates the image and in particular its pixel buffer! */
82  virtual void done2(RawImage & img);
83 
84  //! Get information about a control, throw if unsupported by hardware
85  /*! Caller should zero-out qc and then set the id field to the desired control id. See VIDIOC_QUERYCTRL for more
86  information. */
87  virtual void queryControl(struct v4l2_queryctrl & qc) const = 0;
88 
89  //! Get the available menu entry names for a menu-type control, throw if unsupported by hardware
90  /*! Caller should zero-out qm and then set the id and index fields to the desired control id and menu item
91  index. See VIDIOC_QUERYMENU for more information. */
92  virtual void queryMenu(struct v4l2_querymenu & qm) const = 0;
93 
94  //! Get a control's current value, throw if unsupported by hardware
95  /*! This is just a pass-through to VIDIOC_G_CTRL */
96  virtual void getControl(struct v4l2_control & ctrl) const = 0;
97 
98  //! Set a control, throw if the hardware rejects the value
99  /*! This is just a pass-through to VIDIOC_S_CTRL */
100  virtual void setControl(struct v4l2_control const & ctrl) = 0;
101 
102  //! Set the video format and frame rate
103  virtual void setFormat(VideoMapping const & m) = 0;
104 
105  protected:
106  std::string const itsDevName; //!< Our device or movie file name
107  unsigned int const itsNbufs; //!< Our number of buffers
108  };
109 } // namespace jevois
jevois::VideoInput::VideoInput
VideoInput(std::string const &devname, unsigned int const nbufs=0)
Constructor.
Definition: VideoInput.C:21
jevois::VideoInput
Base class for video input, which will get derived into Camera and MovieInput.
Definition: VideoInput.H:31
RawImage.H
jevois::VideoInput::get
virtual void get(RawImage &img)=0
Get the next captured buffer.
jevois::RawImage
A raw image as coming from a V4L2 Camera and/or being sent out to a USB Gadget.
Definition: RawImage.H:110
jevois::VideoInput::streamOff
virtual void streamOff()=0
Stop streaming.
jevois::VideoInput::~VideoInput
virtual ~VideoInput()
Virtual destructor for save inheritance.
Definition: VideoInput.C:27
jevois::VideoInput::streamOn
virtual void streamOn()=0
Start streaming.
jevois::VideoInput::done
virtual void done(RawImage &img)=0
Indicate that user processing is done with an image previously obtained via get()
jevois
Definition: Concepts.dox:1
jevois::VideoInput::getControl
virtual void getControl(struct v4l2_control &ctrl) const =0
Get a control's current value, throw if unsupported by hardware.
jevois::VideoInput::get2
virtual void get2(RawImage &img)
Get the next captured ISP-scaled secondary buffer.
Definition: VideoInput.C:35
jevois::VideoInput::queryControl
virtual void queryControl(struct v4l2_queryctrl &qc) const =0
Get information about a control, throw if unsupported by hardware.
VideoMapping.H
jevois::VideoInput::setControl
virtual void setControl(struct v4l2_control const &ctrl)=0
Set a control, throw if the hardware rejects the value.
jevois::VideoInput::itsDevName
const std::string itsDevName
Our device or movie file name.
Definition: VideoInput.H:106
jevois::VideoInput::hasScaledImage
virtual bool hasScaledImage() const
Check whether a second input image scaled by the JeVoisPro Platform ISP is available.
Definition: VideoInput.C:31
jevois::VideoInput::itsNbufs
unsigned const int itsNbufs
Our number of buffers.
Definition: VideoInput.H:107
jevois::VideoInput::done2
virtual void done2(RawImage &img)
Indicate that user processing is done with a second ISP-scaled image previously obtained via get2()
Definition: VideoInput.C:39
jevois::VideoInput::abortStream
virtual void abortStream()=0
Abort streaming.
jevois::VideoInput::setFormat
virtual void setFormat(VideoMapping const &m)=0
Set the video format and frame rate.
jevois::VideoInput::queryMenu
virtual void queryMenu(struct v4l2_querymenu &qm) const =0
Get the available menu entry names for a menu-type control, throw if unsupported by hardware.