JeVoisBase
1.22
JeVois Smart Embedded Machine Vision Toolkit Base Modules
|
|
Simple image filtering using OpenGL-ES on the GPU. More...
#include <jevoisbase/Components/FilterGPU/FilterGPU.H>
Public Member Functions | |
FilterGPU (std::string const &instance) | |
Constructor. | |
~FilterGPU () | |
Destructor. | |
void | setProgram (std::string const &vertex_shader, std::string const &frag_shader) |
Set an image processing program. | |
void | setProgramParam2f (std::string name, float val1, float val2) |
Set some program parameters, 2 float version. | |
void | setProgramParam1f (std::string name, float val) |
Set some program parameters, 1 float version. | |
void | setProgramParam2i (std::string name, int val1, int val2) |
Set some program parameters, 2 int version. | |
void | setProgramParam1i (std::string name, int val) |
Set some program parameters, 1 int version. | |
void | process (cv::Mat const &src, cv::Mat &dst) |
Process an image. The dst image should be allocated with correct image size and pixel type. | |
Public Member Functions inherited from jevois::Component | |
Component (std::string const &instance) | |
virtual | ~Component () |
std::shared_ptr< Comp > | addSubComponent (std::string const &instance, Args &&...args) |
void | removeSubComponent (std::shared_ptr< Comp > &component) |
void | removeSubComponent (std::string const &instance, bool warnIfNotFound=true) |
std::shared_ptr< Comp > | getSubComponent (std::string const &instance) const |
bool | isTopLevel () const |
bool | initialized () const |
std::string const & | className () const |
std::string const & | instanceName () const |
std::vector< std::string > | setParamVal (std::string const ¶mdescriptor, T const &val) |
void | setParamValUnique (std::string const ¶mdescriptor, T const &val) |
std::vector< std::pair< std::string, T > > | getParamVal (std::string const ¶mdescriptor) const |
T | getParamValUnique (std::string const ¶mdescriptor) const |
std::vector< std::string > | setParamString (std::string const ¶mdescriptor, std::string const &val) |
void | setParamStringUnique (std::string const ¶mdescriptor, std::string const &val) |
std::vector< std::pair< std::string, std::string > > | getParamString (std::string const ¶mdescriptor) const |
std::string | getParamStringUnique (std::string const ¶mdescriptor) const |
void | freezeParam (std::string const ¶mdescriptor, bool doit) |
void | freezeAllParams (bool doit) |
std::string | descriptor () const |
void | setParamsFromFile (std::string const &filename) |
std::istream & | setParamsFromStream (std::istream &is, std::string const &absfile) |
virtual void | paramInfo (std::shared_ptr< UserInterface > s, std::map< std::string, std::string > &categs, bool skipFrozen, std::string const &cname="", std::string const &pfx="") |
void | foreachParam (std::function< void(std::string const &compname, ParameterBase *p)> func, std::string const &cname="") |
std::shared_ptr< DynamicParameter< T > > | addDynamicParameter (std::string const &name, std::string const &description, T const &defaultValue, ParameterCategory const &category) |
std::shared_ptr< DynamicParameter< T > > | addDynamicParameter (std::string const &name, std::string const &description, T const &defaultValue, ValidValuesSpec< T > const &validValuesSpec, ParameterCategory const &category) |
void | setDynamicParameterCallback (std::string const &name, std::function< void(T const &)> cb, bool callnow=true) |
void | removeDynamicParameter (std::string const &name, bool throw_if_not_found=true) |
void | setPath (std::string const &path) |
std::filesystem::path | absolutePath (std::filesystem::path const &path="") |
std::shared_ptr< Comp > | addSubComponent (std::string const &instance, Args &&...args) |
void | removeSubComponent (std::shared_ptr< Comp > &component) |
void | removeSubComponent (std::string const &instance, bool warnIfNotFound=true) |
std::shared_ptr< Comp > | getSubComponent (std::string const &instance) const |
bool | isTopLevel () const |
bool | initialized () const |
std::string const & | className () const |
std::string const & | instanceName () const |
std::vector< std::string > | setParamVal (std::string const ¶mdescriptor, T const &val) |
void | setParamValUnique (std::string const ¶mdescriptor, T const &val) |
std::vector< std::pair< std::string, T > > | getParamVal (std::string const ¶mdescriptor) const |
T | getParamValUnique (std::string const ¶mdescriptor) const |
std::vector< std::string > | setParamString (std::string const ¶mdescriptor, std::string const &val) |
void | setParamStringUnique (std::string const ¶mdescriptor, std::string const &val) |
std::vector< std::pair< std::string, std::string > > | getParamString (std::string const ¶mdescriptor) const |
std::string | getParamStringUnique (std::string const ¶mdescriptor) const |
void | freezeParam (std::string const ¶mdescriptor, bool doit) |
void | freezeAllParams (bool doit) |
std::string | descriptor () const |
void | setParamsFromFile (std::string const &filename) |
std::istream & | setParamsFromStream (std::istream &is, std::string const &absfile) |
virtual void | paramInfo (std::shared_ptr< UserInterface > s, std::map< std::string, std::string > &categs, bool skipFrozen, std::string const &cname="", std::string const &pfx="") |
void | foreachParam (std::function< void(std::string const &compname, ParameterBase *p)> func, std::string const &cname="") |
std::shared_ptr< DynamicParameter< T > > | addDynamicParameter (std::string const &name, std::string const &description, T const &defaultValue, ParameterCategory const &category) |
std::shared_ptr< DynamicParameter< T > > | addDynamicParameter (std::string const &name, std::string const &description, T const &defaultValue, ValidValuesSpec< T > const &validValuesSpec, ParameterCategory const &category) |
void | setDynamicParameterCallback (std::string const &name, std::function< void(T const &)> cb, bool callnow=true) |
void | removeDynamicParameter (std::string const &name, bool throw_if_not_found=true) |
void | setPath (std::string const &path) |
std::filesystem::path | absolutePath (std::filesystem::path const &path="") |
Public Member Functions inherited from jevois::ParameterRegistry | |
virtual | ~ParameterRegistry () |
Additional Inherited Members | |
Protected Member Functions inherited from jevois::Component | |
virtual void | preInit () |
virtual void | postInit () |
virtual void | preUninit () |
virtual void | postUninit () |
virtual void | preInit () |
virtual void | postInit () |
virtual void | preUninit () |
virtual void | postUninit () |
Protected Member Functions inherited from jevois::ParameterRegistry | |
void | addParameter (ParameterBase *const param) |
void | removeParameter (ParameterBase *const param) |
void | callbackInitCall () |
Simple image filtering using OpenGL-ES on the GPU.
This class first copies the given input image into an OpenGL texture, then applies OpenGL-ES vertex and fragment shaders to achieve some image processing, and finally gets the resulting pixels back into an image.
We support two types of input:
We support two types of output:
Shader conventions:
This code is inspired from the tutorial and code examples found on this page: http://robotblogging.blogspot.com/2013/10/gpu-accelerated-camera-processing-on.html
on host, mesa may be in the way of other drivers, eg nvidia. You need to get them out.
FIXME: yet, this code still does not run on the host. Maybe OpenCV which is using highgui on the host which uses Qt which uses OpenGL (not the ES version) is the issue.
Definition at line 80 of file FilterGPU.H.
FilterGPU::FilterGPU | ( | std::string const & | instance | ) |
Constructor.
Definition at line 21 of file FilterGPU.C.
FilterGPU::~FilterGPU | ( | ) |
Destructor.
Definition at line 62 of file FilterGPU.C.
void FilterGPU::process | ( | cv::Mat const & | src, |
cv::Mat & | dst | ||
) |
Process an image. The dst image should be allocated with correct image size and pixel type.
Definition at line 124 of file FilterGPU.C.
void FilterGPU::setProgram | ( | std::string const & | vertex_shader, |
std::string const & | frag_shader | ||
) |
Set an image processing program.
Definition at line 80 of file FilterGPU.C.
References jevois::Component::absolutePath().
void FilterGPU::setProgramParam1f | ( | std::string | name, |
float | val | ||
) |
Set some program parameters, 1 float version.
Definition at line 100 of file FilterGPU.C.
void FilterGPU::setProgramParam1i | ( | std::string | name, |
int | val | ||
) |
Set some program parameters, 1 int version.
Definition at line 116 of file FilterGPU.C.
void FilterGPU::setProgramParam2f | ( | std::string | name, |
float | val1, | ||
float | val2 | ||
) |
Set some program parameters, 2 float version.
OpenGL is not very thread-friendly. Hence the program chosen using setProgram() will actually be instantiated inside the process() function so everything happens in one thread. Here, users can set program parameters, those are just memorized and will be set in process() as well. Each time setProgram() is called, all cached parameters are cleared and they should be set again.
Definition at line 92 of file FilterGPU.C.
void FilterGPU::setProgramParam2i | ( | std::string | name, |
int | val1, | ||
int | val2 | ||
) |
Set some program parameters, 2 int version.
Definition at line 108 of file FilterGPU.C.