JeVoisBase  1.20
JeVois Smart Embedded Machine Vision Toolkit Base Modules
Share this page:
BufferedVideoReader.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/opencv.hpp>
24 #include <opencv2/videoio.hpp> // for cv::VideoCapture
25 
26 #include <future>
27 #include <atomic>
28 
30 {
31  static jevois::ParameterCategory const ParamCateg("Buffered Video Reader Options");
32 
33  //! Parameter \relates BufferedVideoReader
34  JEVOIS_DECLARE_PARAMETER(filename, std::string, "Filename of video to read (if not absolute, will be assumed to be "
35  "relative to Component path)", "movie.mpg", ParamCateg);
36 
37 }
38 
39 //! Simple class to read video frames from a movie file, decode them, and buffer them for smooth playback
40 /*! Reading and decoding is done in a thread, and decoded images are pushed into a producer/consumer queue. When the
41  queue is full, decoding pauses until some images are popped off the queue by some other thread, for example to
42  display them or to send them over USB link. \ingroup components */
44  public jevois::Parameter<bufferedvideoreader::filename>
45 {
46  public:
47  //! Constructor
48  BufferedVideoReader(std::string const & instance, size_t bufsize = 100);
49 
50  //! Virtual destructor for safe inheritance
52 
53  //! Get the next frame as a BGR cv::Mat, or an empty cv::Mat when the movie is finished
54  cv::Mat get();
55 
56  protected:
57  //! Start the thread that loads, decodes and pushes the frames into our buffer
58  virtual void postInit() override;
59 
60  //! Uninit, wait on our run thread and swallow any exception
61  virtual void postUninit() override;
62 
63  //! Reader thread
64  void run();
65 
66  private:
68  std::future<void> itsRunFut;
69  std::atomic<bool> itsRunning;
70 };
71 
BufferedVideoReader::~BufferedVideoReader
~BufferedVideoReader()
Virtual destructor for safe inheritance.
Definition: BufferedVideoReader.C:27
BufferedVideoReader
Simple class to read video frames from a movie file, decode them, and buffer them for smooth playback...
Definition: BufferedVideoReader.H:43
JEVOIS_DECLARE_PARAMETER
JEVOIS_DECLARE_PARAMETER(thresh1, double, "First threshold for hysteresis", 50.0, ParamCateg)
jevois::Component
jevois::BoundedBuffer< cv::Mat, jevois::BlockingBehavior::Block, jevois::BlockingBehavior::Block >
jevois::ParameterCategory
Component.H
bufferedvideoreader
Definition: BufferedVideoReader.H:29
BufferedVideoReader::BufferedVideoReader
BufferedVideoReader(std::string const &instance, size_t bufsize=100)
Constructor.
Definition: BufferedVideoReader.C:22
BufferedVideoReader::postUninit
virtual void postUninit() override
Uninit, wait on our run thread and swallow any exception.
Definition: BufferedVideoReader.C:47
BufferedVideoReader::get
cv::Mat get()
Get the next frame as a BGR cv::Mat, or an empty cv::Mat when the movie is finished.
Definition: BufferedVideoReader.C:57
BufferedVideoReader::run
void run()
Reader thread.
Definition: BufferedVideoReader.C:61
BufferedVideoReader::postInit
virtual void postInit() override
Start the thread that loads, decodes and pushes the frames into our buffer.
Definition: BufferedVideoReader.C:31
BoundedBuffer.H