JeVoisBase
1.20
JeVois Smart Embedded Machine Vision Toolkit Base Modules
|
Share this page: |
|
|
|
|
|
|
Go to the documentation of this file.
22 #include <opencv2/videoio.hpp>
23 #include <opencv2/imgproc.hpp>
24 #include <linux/videodev2.h>
30 #define PATHPREFIX "/jevois/data/surpriserecorder/"
34 PATHPREFIX " will be prepended to it. Name should contain a printf-like directive for "
35 "one int argument, which will start at 0 and be incremented on each streamoff command.",
36 "video%06d.avi", ParamCateg);
40 "as to which codecs are supported. Presumably, the ffmpeg library is used inside OpenCV. "
41 "Hence any video encoder supported by ffmpeg should work. Tested codecs include: MJPG, "
42 "MP4V, AVC1. Make sure you also pick the right filename extension (e.g., .avi for MJPG, "
43 ".mp4 for MP4V, etc)",
44 "MJPG", boost::regex(
"^\\w{4}$"), ParamCateg);
48 "playback. Beware that the video writer will drop frames if you are capturing faster than "
49 "the frame rate specified here. For example, if capturing at 120fps, be sure to set this "
50 "parameter to 120, otherwise by default the saved video will be at 30fps even though capture "
51 "was running at 120fps.",
60 "each surprising event.",
125 public jevois::Parameter<filename, fourcc, fps, thresh, ctxframes>
134 {
itsSurprise = addSubComponent<Surprise>(
"surprise"); }
165 LINFO(
"Waiting for writer thread to complete, " <<
itsBuf.filled_size() <<
" frames to go...");
167 LINFO(
"Writer thread completed. Syncing disk...");
181 inimg.
require(
"input",
w,
h, V4L2_PIX_FMT_YUYV);
186 std::future<double> itsSurpFut =
214 cv::rectangle(cvimg, cv::Point(3, 3), cv::Point(
w-4,
h-4), cv::Scalar(0,0,255), 7);
262 cv::VideoWriter writer;
268 cv::Mat im =
itsBuf.pop();
271 if (im.empty())
break;
274 if (writer.isOpened() ==
false)
277 std::string
const fcc = fourcc::get();
278 int const cvfcc = cv::VideoWriter::fourcc(fcc[0], fcc[1], fcc[2], fcc[3]);
281 std::string fn = filename::get();
282 if (fn.empty())
LFATAL(
"Cannot save to an empty filename");
286 std::string
const cmd =
"/bin/mkdir -p " + fn.substr(0, fn.rfind(
'/'));
287 if (
std::system(cmd.c_str()))
LERROR(
"Error running [" << cmd <<
"] -- IGNORED");
293 std::snprintf(tmp, 2047, fn.c_str(),
itsFileNum);
294 std::ifstream ifs(tmp);
295 if (ifs.is_open() ==
false) {
itsFilename = tmp;
break; }
300 if (writer.open(
itsFilename, cvfcc, fps::get(), im.size(),
true) ==
false)
SurpriseRecorder(std::string const &instance)
Constructor.
std::atomic< bool > itsRunning
Flag to let run thread when to quit.
std::future< std::invoke_result_t< std::decay_t< Function >, std::decay_t< Args >... > > async(Function &&f, Args &&... args)
Surprise-based recording of events.
void checkpoint(char const *description)
std::shared_ptr< Surprise > itsSurprise
cv::Mat convertToCvBGR(RawImage const &src)
void require(char const *info, unsigned int w, unsigned int h, unsigned int f) const
virtual ~SurpriseRecorder()
Virtual destructor for safe inheritance.
void postUninit() override
Get stopped.
std::string system(std::string const &cmd, bool errtoo=true)
int itsFileNum
Video file number.
void postInit() override
Get started.
std::string itsFilename
Current video file name.
std::future< void > itsRunFut
Future for our run() thread.
std::deque< cv::Mat > itsCtxBuf
Buffer for context frames before event start.
std::string warnAndIgnoreException(std::string const &prefix="")
jevois::BoundedBuffer< cv::Mat, jevois::BlockingBehavior::Block, jevois::BlockingBehavior::Block > itsBuf
Buffer for frames to save.
JEVOIS_REGISTER_MODULE(SurpriseRecorder)
std::string to_string(T const &val)
void process(jevois::InputFrame &&inframe) override
Processing function, version with no video output.
virtual void sendSerial(std::string const &str)
void run()
Video writer thread.
friend friend class Module
int itsToSave
Number of context frames after end of event that remain to be saved.