32 void loadpy(std::string
const & pypath);
35 std::vector<cv::Mat>
process(cv::Mat
const & img,
bool swaprb, std::vector<vsi_nn_tensor_attr_t>
const & attrs,
36 std::vector<cv::Rect> & crops);
59 LINFO(
"Loaded " << pypath);
67 std::vector<vsi_nn_tensor_attr_t>
const & attrs,
68 std::vector<cv::Rect> & crops)
71 boost::python::list alist;
78 if (boost::python::len(ret) != 2)
79 throw std::invalid_argument(
"Expected two return lists for blobs,crops but received " +
80 std::to_string(boost::python::len(ret)));
84#define CROPERR "PreProcessorPython::process: crops should be ( (x,y), (w,h) )"
87 boost::python::list cl = boost::python::extract<boost::python::list>(ret[1]);
88 for (ssize_t i = 0; i < boost::python::len(cl); ++i)
90 boost::python::tuple tup = boost::python::extract<boost::python::tuple>(cl[i]);
91 if (boost::python::len(tup) != 2)
throw std::runtime_error(
CROPERR);
92 boost::python::tuple xy = boost::python::extract<boost::python::tuple>(tup[0]);
93 if (boost::python::len(xy) != 2)
throw std::runtime_error(
CROPERR);
94 boost::python::tuple wh = boost::python::extract<boost::python::tuple>(tup[1]);
95 if (boost::python::len(wh) != 2)
throw std::runtime_error(
CROPERR);
97 float x = boost::python::extract<float>(xy[0]);
98 float y = boost::python::extract<float>(xy[1]);
99 float w = boost::python::extract<float>(wh[0]);
100 float h = boost::python::extract<float>(wh[1]);
101 crops.emplace_back(cv::Rect(x, y, w,
h));
105 boost::python::list ml = boost::python::extract<boost::python::list>(ret[0]);
106 return jevois::python::pyListToVec<cv::Mat>(ml);
132 PythonWrapper::pyinst().attr(
"report")(boost::python::object(), boost::ref(helperpy), overlay, idle);
136 PythonWrapper::pyinst().attr(
"report")(boost::python::object(), boost::python::object(), overlay, idle);
149 itsImpl = addSubComponent<jevois::dnn::PreProcessorPythonImpl>(
"pypre");
163 itsImpl->freeze(doit);
168 std::string
const & newval)
170 if (newval.empty() ==
false) itsImpl->loadpy(newval);
175 std::vector<vsi_nn_tensor_attr_t>
const & attrs,
176 std::vector<cv::Rect> & crops)
177{
return itsImpl->process(img, swaprb, attrs, crops); }
182{ itsImpl->report(mod, outimg, helper, overlay, idle); }
#define JEVOIS_SHARE_PATH
Base path for shared files (e.g., neural network weights, etc)
A component of a model hierarchy.
Wrapper around GUIhelper to be used by Python.
Helper class to assist modules in creating graphical and GUI elements.
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.
Base class for a module that supports standardized serial messages.
void report(jevois::StdModule *mod, jevois::RawImage *outimg=nullptr, jevois::OptGUIhelper *helper=nullptr, bool overlay=true, bool idle=false)
std::vector< cv::Mat > process(cv::Mat const &img, bool swaprb, std::vector< vsi_nn_tensor_attr_t > const &attrs, std::vector< cv::Rect > &crops)
virtual ~PreProcessorPythonImpl()
void loadpy(std::string const &pypath)
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.
std::shared_ptr< PreProcessorPythonImpl > itsImpl
std::vector< cv::Mat > process(cv::Mat const &img, bool swaprb, std::vector< vsi_nn_tensor_attr_t > const &attrs, std::vector< cv::Rect > &crops) override
Extract blobs from input image.
virtual ~PreProcessorPython()
Destructor.
void freeze(bool doit) override
Freeze/unfreeze parameters that users should not change while running.
PreProcessorPython(std::string const &instance)
Constructor.
void onParamChange(preprocessor::pypre const ¶m, std::string const &newval) override
Pre-Processor for neural network pipeline.
#define LINFO(msg)
Convenience macro for users to print out console or syslog messages, INFO level.
std::string attrstr(vsi_nn_tensor_attr_t const &attr)
Get a string describing the specs of a tensor, including quantification specs (not provided by shapes...
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.