JeVois
1.22
JeVois Smart Embedded Machine Vision Toolkit
|
|
#include <jevois/Core/PythonWrapper.H>
Helper class to run python code from C++.
This class loads python code and makes it accessible through pyinst(). It is designed to be composed with other classes that will actually execute some python code via pyinst().
The main convention here is that the python code will define a class with the exact same name as the python filename (without trailing .py extension). This is the class that will then become accessible via pyinst().
Note that constructors and pythonload() will not throw, but pyinst() will if an error occurred at construction.
Often this class is inherited from by a class that also inherits from Component, to create a Component derivative that can run python code. In such case, PythonWrapper will register that sibling association with Engine when the python code is loaded. It is critical that you inherit from Component (or a derivative) before you inherit from PythonWrapper, so that by the time the PythonWrapper destructor is called the Component base should not yet have been destroyed, and it will be unregistered from Engine.
Definition at line 41 of file PythonWrapper.H.
Public Member Functions | |
PythonWrapper () | |
Default constructor. Will need to call pythonload() later. | |
virtual | ~PythonWrapper () |
Destructor. | |
PythonWrapper (std::string const &path) | |
Construct from path. | |
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) | |
boost::python::object & | mainModule () |
Get the main module. | |
boost::python::object & | mainNamespace () |
Get the main namespace. | |
std::string const & | constructionError () const |
Get the construction error if any, or empty string. | |
jevois::PythonWrapper::PythonWrapper | ( | ) |
Default constructor. Will need to call pythonload() later.
Definition at line 23 of file PythonWrapper.C.
|
virtual |
Destructor.
Definition at line 104 of file PythonWrapper.C.
jevois::PythonWrapper::PythonWrapper | ( | std::string const & | path | ) |
Construct from path.
Definition at line 28 of file PythonWrapper.C.
std::string const & jevois::PythonWrapper::constructionError | ( | ) | const |
Get the construction error if any, or empty string.
Definition at line 100 of file PythonWrapper.C.
boost::python::object & jevois::PythonWrapper::mainModule | ( | ) |
Get the main module.
Definition at line 92 of file PythonWrapper.C.
boost::python::object & jevois::PythonWrapper::mainNamespace | ( | ) |
Get the main namespace.
Definition at line 96 of file PythonWrapper.C.
boost::python::object & jevois::PythonWrapper::pyinst | ( | ) |
Get the python class pyinst, or throw if construction error occurred (e.g., file not found)
Definition at line 85 of file PythonWrapper.C.
Referenced by jevois::dnn::NetworkPythonImpl::doprocess(), jevois::dnn::NetworkPythonImpl::freeze(), jevois::dnn::PostProcessorPythonImpl::freeze(), jevois::dnn::PreProcessorPythonImpl::freeze(), jevois::dnn::NetworkPythonImpl::load(), jevois::dnn::NetworkPythonImpl::loadpy(), jevois::dnn::PostProcessorPythonImpl::loadpy(), jevois::dnn::PreProcessorPythonImpl::loadpy(), jevois::PythonModule::parseSerial(), jevois::PythonModule::postUninit(), jevois::PythonModule::preInit(), jevois::dnn::PreProcessorPythonImpl::process(), jevois::PythonModule::process(), jevois::PythonModule::process(), jevois::PythonModule::process(), jevois::dnn::PostProcessorPythonImpl::process(), jevois::dnn::PostProcessorPythonImpl::report(), jevois::dnn::PreProcessorPythonImpl::report(), and jevois::PythonModule::supportedCommands().
void jevois::PythonWrapper::pythonload | ( | std::string const & | path | ) |
Init from path if default constructor was used.
Definition at line 34 of file PythonWrapper.C.
References jevois::getPythonExceptionString(), JEVOIS_CONFIG_PATH, JEVOIS_OPENCV_PYTHON_PATH, and JEVOIS_ROOT_PATH.
Referenced by jevois::dnn::NetworkPythonImpl::loadpy(), jevois::dnn::PostProcessorPythonImpl::loadpy(), jevois::dnn::PreProcessorPythonImpl::loadpy(), and jevois::PythonModule::preInit().