JeVois  1.5
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
MovieInput.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/Core/VideoInput.H>
22 
23 #include <opencv2/videoio.hpp> // for cv::VideoCapture
24 
25 namespace jevois
26 {
27  //! Movie input, can be used as a replacement for Camera to debug algorithms using a fixed video sequence
28  /*! The movie will be looped forever to provide continual input. This is a direct wrapper around the VideoCapture
29  class of OpenCV, and it hence supports many different video file formats, and image sequences when the filename
30  contains a printf-like %d placeholder for a frame number. See OpenCV documentation for VideoCapture for more
31  details.
32 
33  Note that the movie frames will be resized to match the dimensions specified by setFormat() and will be converted
34  to the pixel type specified in setFormat(). \ingroup core */
35  class MovieInput : public VideoInput
36  {
37  public:
38  //! Constructor, opens the movie file
39  MovieInput(std::string const & filename, unsigned int const nbufs = 3);
40 
41  //! Virtual destructor for save inheritance
42  virtual ~MovieInput();
43 
44  //! Start streaming
45  virtual void streamOn() override;
46 
47  //! Abort streaming
48  /*! This only cancels future get() and done() calls, one should still call streamOff() to turn off streaming. */
49  virtual void abortStream() override;
50 
51  //! Stop streaming
52  virtual void streamOff() override;
53 
54  //! Get the next frame from the video file, possibly looping back to start if end is reached
55  virtual void get(RawImage & img) override;
56 
57  //! Indicate that user processing is done with an image previously obtained via get()
58  /*! You should call this as soon after get() as possible, once you are finished with the RawImage data so that it
59  can be recycled. This also invalidates the image and in particular its pixel buffer. */
60  virtual void done(RawImage & img) override;;
61 
62  //! Get information about a control, throw if unsupported by hardware
63  /*! In MovieInput, this just throws an std::runtime_error */
64  virtual void queryControl(struct v4l2_queryctrl & qc) const override;
65 
66  //! Get the available menu entry names for a menu-type control, throw if unsupported by hardware
67  /*! In MovieInput, this just throws an std::runtime_error */
68  virtual void queryMenu(struct v4l2_querymenu & qm) const override;
69 
70  //! Get a control's current value, throw if unsupported by hardware
71  /*! In MovieInput, this just throws an std::runtime_error */
72  virtual void getControl(struct v4l2_control & ctrl) const override;
73 
74  //! Set a control, throw if the hardware rejects the value
75  /*! In MovieInput, this just throws an std::runtime_error */
76  virtual void setControl(struct v4l2_control const & ctrl) override;
77 
78  //! Set the video format and frame rate
79  /*! Video frames read from the input movie file will be rescaled (if necessary) to that format's resolution, and
80  will be converted (if necessary) to that format's pixel type. */
81  virtual void setFormat(VideoMapping const & m) override;
82 
83  //! Write a value of one of the camera's registers
84  /*! In MovieInput, this just throws an std::runtime_error */
85  virtual void writeRegister(unsigned char reg, unsigned char val) override;
86 
87  //! Read a value from one of the camera's registers
88  /*! In MovieInput, this just throws an std::runtime_error */
89  virtual unsigned char readRegister(unsigned char reg) override;
90 
91  protected:
92  cv::VideoCapture itsCap; //!< Our OpenCV video capture, works on movie and image files too
93  std::shared_ptr<VideoBuf> itsBuf; //!< Our single video buffer
94  VideoMapping itsMapping; //!< Our current video mapping, we resize the input to the mapping's camera dims
95  };
96 } // namespace jevois
virtual void queryControl(struct v4l2_queryctrl &qc) const override
Get information about a control, throw if unsupported by hardware.
Definition: MovieInput.C:99
virtual void writeRegister(unsigned char reg, unsigned char val) override
Write a value of one of the camera&#39;s registers.
Definition: MovieInput.C:122
virtual void abortStream() override
Abort streaming.
Definition: MovieInput.C:43
virtual void queryMenu(struct v4l2_querymenu &qm) const override
Get the available menu entry names for a menu-type control, throw if unsupported by hardware...
Definition: MovieInput.C:103
virtual void streamOff() override
Stop streaming.
Definition: MovieInput.C:47
MovieInput(std::string const &filename, unsigned int const nbufs=3)
Constructor, opens the movie file.
Definition: MovieInput.C:27
virtual void streamOn() override
Start streaming.
Definition: MovieInput.C:39
virtual void setFormat(VideoMapping const &m) override
Set the video format and frame rate.
Definition: MovieInput.C:115
A raw image as coming from a V4L2 Camera and/or being sent out to a USB Gadget.
Definition: RawImage.H:110
Simple struct to hold video mapping definitions for the processing Engine.
Definition: VideoMapping.H:41
virtual void done(RawImage &img) override
Indicate that user processing is done with an image previously obtained via get() ...
Definition: MovieInput.C:92
virtual void getControl(struct v4l2_control &ctrl) const override
Get a control&#39;s current value, throw if unsupported by hardware.
Definition: MovieInput.C:107
Base class for video input, which will get derived into Camera and MovieInput.
Definition: VideoInput.H:31
virtual void setControl(struct v4l2_control const &ctrl) override
Set a control, throw if the hardware rejects the value.
Definition: MovieInput.C:111
Movie input, can be used as a replacement for Camera to debug algorithms using a fixed video sequence...
Definition: MovieInput.H:35
virtual unsigned char readRegister(unsigned char reg) override
Read a value from one of the camera&#39;s registers.
Definition: MovieInput.C:126
virtual ~MovieInput()
Virtual destructor for save inheritance.
Definition: MovieInput.C:35
VideoMapping itsMapping
Our current video mapping, we resize the input to the mapping&#39;s camera dims.
Definition: MovieInput.H:94
std::shared_ptr< VideoBuf > itsBuf
Our single video buffer.
Definition: MovieInput.H:93
cv::VideoCapture itsCap
Our OpenCV video capture, works on movie and image files too.
Definition: MovieInput.H:92