JeVoisBase
1.22
JeVois Smart Embedded Machine Vision Toolkit Base Modules
|
|
Detect multiple objects in scenes using the Darknet YOLO deep neural network. More...
Public Member Functions | |
DarknetYOLO (std::string const &instance) | |
Constructor. | |
virtual | ~DarknetYOLO () |
Virtual destructor for safe inheritance. | |
virtual void | postUninit () override |
Un-initialization. | |
virtual void | process (jevois::InputFrame &&inframe) override |
Processing function, no video output. | |
virtual void | process (jevois::InputFrame &&inframe, jevois::OutputFrame &&outframe) override |
Processing function with video output to USB. | |
Public Member Functions inherited from jevois::StdModule | |
StdModule (std::string const &instance) | |
virtual | ~StdModule () |
void | sendSerialImg1Dx (unsigned int camw, float x, float size=0.0F, std::string const &id="", std::string const &extra="") |
void | sendSerialStd1Dx (float x, float size=0.0F, std::string const &id="", std::string const &extra="") |
void | sendSerialImg1Dy (unsigned int camh, float y, float size=0.0F, std::string const &id="", std::string const &extra="") |
void | sendSerialStd1Dy (float y, float size=0.0F, std::string const &id="", std::string const &extra="") |
void | sendSerialImg2D (unsigned int camw, unsigned int camh, float x, float y, float w=0.0F, float h=0.0F, std::string const &id="", std::string const &extra="") |
void | sendSerialStd2D (float x, float y, float w=0.0F, float h=0.0F, std::string const &id="", std::string const &extra="") |
void | sendSerialContour2D (unsigned int camw, unsigned int camh, std::vector< cv::Point_< T > > points, std::string const &id="", std::string const &extra="") |
void | sendSerialStd3D (float x, float y, float z, float w=0.0F, float h=0.0F, float d=0.0F, float q1=0.0F, float q2=0.0F, float q3=0.0f, float q4=0.0F, std::string const &id="", std::string const &extra="") |
void | sendSerialStd3D (std::vector< cv::Point3f > points, std::string const &id="", std::string const &extra="") |
void | sendSerialObjReco (std::vector< ObjReco > const &res) |
void | sendSerialObjDetImg2D (unsigned int camw, unsigned int camh, float x, float y, float w, float h, std::vector< ObjReco > const &res) |
void | sendSerialObjDetImg2D (unsigned int camw, unsigned int camh, ObjDetect const &det) |
void | sendSerialObjDetImg2D (unsigned int camw, unsigned int camh, ObjDetectOBB const &det) |
JEVOIS_DEFINE_ENUM_CLASS (SerStyle,(Terse)(Normal)(Detail)(Fine)) | |
JEVOIS_DECLARE_PARAMETER (serstyle, SerStyle, "Style for standardized serial messages as defined in " "http://jevois.org/doc/UserSerialStyle.html", SerStyle::Terse, SerStyle_Values, ParamCateg) | |
JEVOIS_DECLARE_PARAMETER (serprec, unsigned int, "Number of decimal points in standardized serial messages as " "defined in http://jevois.org/doc/UserSerialStyle.html", 0U, jevois::Range< unsigned int >(0U, 10U), ParamCateg) | |
JEVOIS_DEFINE_ENUM_CLASS (SerStamp,(None)(Frame)(Time)(FrameTime)(FrameDateTime)) | |
JEVOIS_DECLARE_PARAMETER (serstamp, SerStamp, "Prepend standardized serial messages with a frame number, " "time, frame+time, or frame+date+time. See details in " "http://jevois.org/doc/UserSerialStyle.html", SerStamp::None, SerStamp_Values, ParamCateg) | |
JEVOIS_DEFINE_ENUM_CLASS (SerMark,(None)(Start)(Stop)(Both)) | |
JEVOIS_DECLARE_PARAMETER (sermark, SerMark, "Send serial message to mark the beginning (MARK START) of the " "processing of a video frame from the camera sensor, the end (MARK STOP), or both. " "Useful, among others, if one needs to know when no results were sent over serial " "on a given frame. Combine with parameter serstamp if you need to know the frame number.", SerMark::None, SerMark_Values, ParamCateg) | |
Public Member Functions inherited from jevois::Module | |
Module (std::string const &instance) | |
virtual | ~Module () |
virtual void | process (InputFrame &&inframe, GUIhelper &helper) |
virtual void | sendSerial (std::string const &str) |
virtual void | parseSerial (std::string const &str, std::shared_ptr< UserInterface > s) |
virtual void | supportedCommands (std::ostream &os) |
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 () |
Protected Attributes | |
std::shared_ptr< Yolo > | itsYolo |
std::future< float > | itsPredictFut |
cv::Mat | itsRawInputCv |
cv::Mat | itsRawPrevOutputCv |
cv::Mat | itsNetInput |
Related Symbols | |
(Note that these are not member symbols.) | |
JEVOIS_DECLARE_PARAMETER (netin, cv::Size, "Width and height (in pixels) of the neural network input layer, or [0 0] " "to make it match camera frame size. NOTE: for YOLO v3 sizes must be multiples of 32.", cv::Size(320, 224), ParamCateg) | |
Parameter. | |
Additional Inherited Members | |
Protected Member Functions inherited from jevois::StdModule | |
void | sendSerialMarkStart () |
void | sendSerialMarkStop () |
std::string | getStamp () const |
Protected Member Functions inherited from jevois::Component | |
virtual void | preInit () |
virtual void | postInit () |
virtual void | preUninit () |
virtual void | preInit () |
virtual void | postInit () |
virtual void | preUninit () |
Protected Member Functions inherited from jevois::ParameterRegistry | |
void | addParameter (ParameterBase *const param) |
void | removeParameter (ParameterBase *const param) |
void | callbackInitCall () |
Detect multiple objects in scenes using the Darknet YOLO deep neural network.
Darknet is a popular neural network framework, and YOLO is a very interesting network that detects all objects in a scene in one pass. This module detects all instances of any of the objects it knows about (determined by the network structure, labels, dataset used for training, and weights obtained) in the image that is given to it.
See https://pjreddie.com/darknet/yolo/
This module runs a YOLO network and shows all detections obtained. The YOLO network is currently quite slow, hence it is only run once in a while. Point your camera towards some interesting scene, keep it stable, and wait for YOLO to tell you what it found. The framerate figures shown at the bottom left of the display reflect the speed at which each new video frame from the camera is processed, but in this module this just amounts to converting the image to RGB, sending it to the neural network for processing in a separate thread, and creating the demo display. Actual network inference speed (time taken to compute the predictions on one image) is shown at the bottom right. See below for how to trade-off speed and accuracy.
Note that by default this module runs tiny-YOLO V3 which can detect and recognize 80 different kinds of objects from the Microsoft COCO dataset. This module can also run tiny-YOLO V2 for COCO, or tiny-YOLO V2 for the Pascal-VOC dataset with 20 object categories. See the module's params.cfg file to switch network.
Sometimes it will make mistakes! The performance of yolov3-tiny is about 33.1% correct (mean average precision) on the COCO test set.
The parameter netin
allows you to rescale the neural network to the specified size. Beware that this will only work if the network used is fully convolutional (as is the case of the default tiny-yolo network). This not only allows you to adjust processing speed (and, conversely, accuracy), but also to better match the network to the input images (e.g., the default size for tiny-yolo is 416x416, and, thus, passing it a input image of size 640x480 will result in first scaling that input to 416x312, then letterboxing it by adding gray borders on top and bottom so that the final input to the network is 416x416). This letterboxing can be completely avoided by just resizing the network to 320x240.
Here are expected processing speeds for yolov2-tiny-voc:
YOLO V3 is faster, more accurate, uses less memory, and can detect 80 COCO categories:
When detections are found which are above threshold, one message will be sent for each detected object (i.e., for each box that gets drawn when USB outputs are used), using a standardized 2D message:
id
: the category of the recognized object, followed by ':' and the confidence score in percentx
, y
, or vertices: standardized 2D coordinates of object center or cornersw
, h
: standardized object sizeextra
: any number of additional category:score pairs which had an above-threshold score for that boxSee Standardized serial messages formatting for more on standardized serial messages, and Helper functions to convert coordinates from camera resolution to standardized for more info on standardized coordinates.
Definition at line 119 of file DarknetYOLO.C.
|
inline |
|
inlinevirtual |
Virtual destructor for safe inheritance.
Definition at line 134 of file DarknetYOLO.C.
|
inlineoverridevirtual |
Un-initialization.
Reimplemented from jevois::Component.
Definition at line 140 of file DarknetYOLO.C.
References itsPredictFut.
|
inlineoverridevirtual |
Processing function, no video output.
Reimplemented from jevois::Module.
Definition at line 148 of file DarknetYOLO.C.
References jevois::rawimage::convertToCvRGB(), h, jevois::RawImage::height, itsNetInput, itsYolo, LINFO, jevois::rescaleCv(), and jevois::RawImage::width.
|
inlineoverridevirtual |
Processing function with video output to USB.
Reimplemented from jevois::Module.
Definition at line 195 of file DarknetYOLO.C.
References jevois::async(), jevois::yuyv::Black, jevois::rawimage::convertToCvRGB(), jevois::rawimage::cvImage(), jevois::rawimage::drawFilledRect(), jevois::RawImage::fmt, h, jevois::RawImage::height, itsNetInput, itsPredictFut, itsRawInputCv, itsRawPrevOutputCv, itsYolo, jevois::rawimage::paste(), jevois::RawImage::require(), jevois::rescaleCv(), jevois::Timer::start(), jevois::Timer::stop(), success, jevois::yuyv::White, jevois::RawImage::width, and jevois::rawimage::writeText().
|
related |
Parameter.
|
protected |
Definition at line 337 of file DarknetYOLO.C.
|
protected |
Definition at line 334 of file DarknetYOLO.C.
Referenced by postUninit(), and process().
|
protected |
Definition at line 335 of file DarknetYOLO.C.
Referenced by process().
|
protected |
Definition at line 336 of file DarknetYOLO.C.
Referenced by process().
|
protected |
Definition at line 333 of file DarknetYOLO.C.
Referenced by DarknetYOLO(), process(), and process().