JeVois  1.22
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
Loading...
Searching...
No Matches
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
22
23#include <opencv2/videoio.hpp> // for cv::VideoCapture
24
25namespace 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 safe inheritance
42 virtual ~MovieInput();
43
44 //! Start streaming
45 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 void abortStream() override;
50
51 //! Stop streaming
52 void streamOff() override;
53
54 //! Get the next frame from the video file, possibly looping back to start if end is reached
55 void get(RawImage & img) override;
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 override;
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) override;
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. This also invalidates the image and in particular its pixel buffer. */
73 void done(RawImage & img) override;
74
75 //! Indicate that user processing is done with an image previously obtained via get()
76 /*! You should call this as soon after get() as possible, once you are finished with the RawImage data so that it
77 can be recycled. This also invalidates the image and in particular its pixel buffer. */
78 void done2(RawImage & img) override;
79
80 //! Get information about a control, throw if unsupported by hardware
81 /*! In MovieInput, this just throws an std::runtime_error */
82 void queryControl(struct v4l2_queryctrl & qc) const override;
83
84 //! Get the available menu entry names for a menu-type control, throw if unsupported by hardware
85 /*! In MovieInput, this just throws an std::runtime_error */
86 void queryMenu(struct v4l2_querymenu & qm) const override;
87
88 //! Get a control's current value, throw if unsupported by hardware
89 /*! In MovieInput, this just throws an std::runtime_error */
90 void getControl(struct v4l2_control & ctrl) const override;
91
92 //! Set a control, throw if the hardware rejects the value
93 /*! In MovieInput, this just throws an std::runtime_error */
94 void setControl(struct v4l2_control const & ctrl) override;
95
96 //! Set the video format and frame rate
97 /*! Video frames read from the input movie file will be rescaled (if necessary) to that format's resolution, and
98 will be converted (if necessary) to that format's pixel type. */
99 void setFormat(VideoMapping const & m) override;
100
101 protected:
102 cv::VideoCapture itsCap; //!< Our OpenCV video capture, works on movie and image files too
103 cv::Mat itsRawFrame; //!< Raw OpenCV frame last captured, before any resizing or conversion
104 std::shared_ptr<VideoBuf> itsBuf; //!< Our single video buffer for the main frame
105 std::shared_ptr<VideoBuf> itsBuf2; //!< Our single video buffer for the second (processing) frame
106 VideoMapping itsMapping; //!< Our current video mapping, we resize the input to the mapping's camera dims
107 };
108
109} // namespace jevois
Movie input, can be used as a replacement for Camera to debug algorithms using a fixed video sequence...
Definition MovieInput.H:36
virtual bool hasScaledImage() const override
Check whether a second input image scaled by the JeVoisPro Platform ISP is available.
Definition MovieInput.C:51
void setFormat(VideoMapping const &m) override
Set the video format and frame rate.
Definition MovieInput.C:200
virtual ~MovieInput()
Virtual destructor for safe inheritance.
Definition MovieInput.C:35
VideoMapping itsMapping
Our current video mapping, we resize the input to the mapping's camera dims.
Definition MovieInput.H:106
void get(RawImage &img) override
Get the next frame from the video file, possibly looping back to start if end is reached.
Definition MovieInput.C:57
void streamOn() override
Start streaming.
Definition MovieInput.C:39
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:188
void getControl(struct v4l2_control &ctrl) const override
Get a control's current value, throw if unsupported by hardware.
Definition MovieInput.C:192
void done(RawImage &img) override
Indicate that user processing is done with an image previously obtained via get()
Definition MovieInput.C:169
std::shared_ptr< VideoBuf > itsBuf2
Our single video buffer for the second (processing) frame.
Definition MovieInput.H:105
cv::VideoCapture itsCap
Our OpenCV video capture, works on movie and image files too.
Definition MovieInput.H:102
cv::Mat itsRawFrame
Raw OpenCV frame last captured, before any resizing or conversion.
Definition MovieInput.H:103
void queryControl(struct v4l2_queryctrl &qc) const override
Get information about a control, throw if unsupported by hardware.
Definition MovieInput.C:184
void done2(RawImage &img) override
Indicate that user processing is done with an image previously obtained via get()
Definition MovieInput.C:177
void streamOff() override
Stop streaming.
Definition MovieInput.C:47
virtual void get2(RawImage &img) override
Get the next captured ISP-scaled secondary buffer.
Definition MovieInput.C:116
void setControl(struct v4l2_control const &ctrl) override
Set a control, throw if the hardware rejects the value.
Definition MovieInput.C:196
std::shared_ptr< VideoBuf > itsBuf
Our single video buffer for the main frame.
Definition MovieInput.H:104
void abortStream() override
Abort streaming.
Definition MovieInput.C:43
A raw image as coming from a V4L2 Camera and/or being sent out to a USB Gadget.
Definition RawImage.H:111
Base class for video input, which will get derived into Camera and MovieInput.
Definition VideoInput.H:32
Main namespace for all JeVois classes and functions.
Definition Concepts.dox:2
Simple struct to hold video mapping definitions for the processing Engine.