JeVois  1.21
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
Loading...
Searching...
No Matches
PostProcessorPython.C
Go to the documentation of this file.
1// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2//
3// JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2021 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
22
23// ####################################################################################################
24namespace jevois
25{
26 namespace dnn
27 {
29 {
30 public:
32 void loadpy(std::string const & pypath);
34 void freeze(bool doit);
35 void process(std::vector<cv::Mat> const & outs, PreProcessor * preproc);
36 void report(jevois::StdModule * mod, jevois::RawImage * outimg = nullptr,
37 jevois::OptGUIhelper * helper = nullptr, bool overlay = true, bool idle = false);
38 };
39 }
40}
41
42// ####################################################################################################
43// ####################################################################################################
46
47// ####################################################################################################
52
53// ####################################################################################################
54void jevois::dnn::PostProcessorPythonImpl::loadpy(std::string const & pypath)
55{
56 // Load the code and instantiate the python object:
58 LINFO("Loaded " << pypath);
59
60 // Now that we are fully up and ready, call python module's init() function if implemented:
62}
63
64// ####################################################################################################
65void jevois::dnn::PostProcessorPythonImpl::process(std::vector<cv::Mat> const & outs,
67{
68 boost::python::list lst = jevois::python::pyVecToList(outs);
69 PythonWrapper::pyinst().attr("process")(lst, boost::python::ptr(preproc->getPreProcForPy().get()));
70}
71
72// ####################################################################################################
74 jevois::OptGUIhelper * helper, bool overlay, bool idle)
75{
76 // default constructed boost::python::object is None on the python side
77 if (outimg)
78 {
79#ifdef JEVOIS_PRO
80 if (helper)
81 {
82 jevois::GUIhelperPython helperpy(helper);
83 PythonWrapper::pyinst().attr("report")(boost::ref(*outimg), boost::ref(helperpy), overlay, idle);
84 }
85 else
86#endif
87 PythonWrapper::pyinst().attr("report")(boost::ref(*outimg), boost::python::object(), overlay, idle);
88 }
89 else
90 {
91#ifdef JEVOIS_PRO
92 if (helper)
93 {
94 jevois::GUIhelperPython helperpy(helper);
95 PythonWrapper::pyinst().attr("report")(boost::python::object(), boost::ref(helperpy), overlay, idle);
96 }
97 else
98#endif
99 PythonWrapper::pyinst().attr("report")(boost::python::object(), boost::python::object(), overlay, idle);
100 }
101
102#ifndef JEVOIS_PRO
103 (void)helper; // avoid compiler warning
104#endif
105}
106
107// ####################################################################################################
108// ####################################################################################################
110 jevois::dnn::PostProcessor(instance)
111{
112 itsImpl = addSubComponent<jevois::dnn::PostProcessorPythonImpl>("pypost");
113}
114
115// ####################################################################################################
118
119// ####################################################################################################
121{
122 // First our own params:
123 pypost::freeze(doit);
124
125 // Then our python params:
126 itsImpl->freeze(doit);
127}
128
129// ####################################################################################################
130void jevois::dnn::PostProcessorPython::onParamChange(jevois::dnn::postprocessor::pypost const &,
131 std::string const & newval)
132{
133 if (newval.empty() == false) itsImpl->loadpy(newval);
134}
135
136// ####################################################################################################
137void jevois::dnn::PostProcessorPython::process(std::vector<cv::Mat> const & outs, jevois::dnn::PreProcessor * preproc)
138{ itsImpl->process(outs, preproc); }
139
140// ####################################################################################################
142 jevois::OptGUIhelper * helper, bool overlay, bool idle)
143{ itsImpl->report(mod, outimg, helper, overlay, idle); }
144
#define JEVOIS_SHARE_PATH
Base path for shared files (e.g., neural network weights, etc)
Definition Config.H:82
A component of a model hierarchy.
Definition Component.H:182
Wrapper around GUIhelper to be used by Python.
Helper class to assist modules in creating graphical and GUI elements.
Definition GUIhelper.H:133
friend class Component
Allow Component and DynamicParameter to access our registry data, everyone else is locked out.
Helper class to run python code from C++.
void pythonload(std::string const &path)
Init from path if default constructor was used.
boost::python::object & pyinst()
Get the python class pyinst, or throw if construction error occurred (e.g., file not found)
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 a module that supports standardized serial messages.
Definition Module.H:234
void loadpy(std::string const &pypath)
void process(std::vector< cv::Mat > const &outs, PreProcessor *preproc)
void report(jevois::StdModule *mod, jevois::RawImage *outimg=nullptr, jevois::OptGUIhelper *helper=nullptr, bool overlay=true, bool idle=false)
std::shared_ptr< PostProcessorPythonImpl > itsImpl
void process(std::vector< cv::Mat > const &outs, PreProcessor *preproc) override
Process outputs and draw/send some results.
void report(jevois::StdModule *mod, jevois::RawImage *outimg=nullptr, jevois::OptGUIhelper *helper=nullptr, bool overlay=true, bool idle=false) override
Report what happened in last process() to console/output video/GUI.
void freeze(bool doit) override
Freeze/unfreeze parameters that users should not change while running.
PostProcessorPython(std::string const &instance)
Constructor.
void onParamChange(postprocessor::pypost const &param, std::string const &newval) override
Post-Processor for neural network pipeline.
Pre-Processor for neural network pipeline.
std::shared_ptr< PreProcessorForPython > getPreProcForPy() const
Get a pointer to our python-friendly interface.
#define LINFO(msg)
Convenience macro for users to print out console or syslog messages, INFO level.
Definition Log.H:194
boost::python::list pyVecToList(std::vector< T > const &v)
Helper to convert std::vector<T> to python list.
bool hasattr(boost::python::object &o, char const *name)
Check whether a boost::python::object has an attribute.
Main namespace for all JeVois classes and functions.
Definition Concepts.dox:2