33        void loadpy(std::string 
const & pypath);
 
   36        std::vector<cv::Mat> 
process(cv::Mat 
const & img, 
bool swaprb, std::vector<vsi_nn_tensor_attr_t> 
const & attrs,
 
   37                                     std::vector<cv::Rect> & crops);
 
 
   62  LINFO(
"Loaded " << pypath);
 
 
   70                                                                  std::vector<vsi_nn_tensor_attr_t> 
const & attrs,
 
   71                                                                  std::vector<cv::Rect> & crops)
 
   74    LFATAL(
"No process() method provided. It is required, please add it to your Python pre-processor.");
 
   77  boost::python::list alist;
 
   84  if (boost::python::len(ret) != 2)
 
   85    throw std::invalid_argument(
"Expected two return lists for blobs,crops but received " +
 
   86                                std::to_string(boost::python::len(ret)));
 
   90#define CROPERR "PreProcessorPython::process: crops should be ( (x,y), (w,h) )" 
   93  boost::python::list cl = boost::python::extract<boost::python::list>(ret[1]);
 
   94  for (ssize_t i = 0; i < boost::python::len(cl); ++i)
 
   96    boost::python::tuple tup = boost::python::extract<boost::python::tuple>(cl[i]);
 
   97    if (boost::python::len(tup) != 2) 
throw std::runtime_error(
CROPERR);
 
   98    boost::python::tuple xy = boost::python::extract<boost::python::tuple>(tup[0]);
 
   99    if (boost::python::len(xy) != 2) 
throw std::runtime_error(
CROPERR);
 
  100    boost::python::tuple wh = boost::python::extract<boost::python::tuple>(tup[1]);
 
  101    if (boost::python::len(wh) != 2) 
throw std::runtime_error(
CROPERR);
 
  103    float x = boost::python::extract<float>(xy[0]);
 
  104    float y = boost::python::extract<float>(xy[1]);
 
  105    float w = boost::python::extract<float>(wh[0]);
 
  106    float h = boost::python::extract<float>(wh[1]);
 
  107    crops.emplace_back(cv::Rect(x, y, w, 
h));
 
  111  boost::python::list ml = boost::python::extract<boost::python::list>(ret[0]);
 
  112  return jevois::python::pyListToVec<cv::Mat>(ml);
 
 
  120    LFATAL(
"No process() method provided. It is required, please add it to your Python pre-processor.");
 
  141      PythonWrapper::pyinst().attr(
"report")(boost::python::object(), boost::ref(helperpy), overlay, idle);
 
  145      PythonWrapper::pyinst().attr(
"report")(boost::python::object(), boost::python::object(), overlay, idle);
 
 
  158  itsImpl = addSubComponent<jevois::dnn::PreProcessorPythonImpl>(
"pypre");
 
 
  172  itsImpl->freeze(doit);
 
 
  177                                                    std::string 
const & newval)
 
  179  if (newval.empty() == 
false) itsImpl->loadpy(newval);
 
 
  184                                                              std::vector<vsi_nn_tensor_attr_t> 
const & attrs,
 
  185                                                              std::vector<cv::Rect> & crops)
 
  186{ 
return itsImpl->process(img, swaprb, attrs, crops); }
 
 
  191{ 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.
void unRegisterPythonComponent(Component *comp)
Unregister a component as linked to some python code, used by dynamic params created in python.
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 LFATAL(msg)
Convenience macro for users to print out console or syslog messages, FATAL level.
#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.