JeVoisBase  1.22
JeVois Smart Embedded Machine Vision Toolkit Base Modules
Share this page:
Loading...
Searching...
No Matches
MultiDNN2.C
Go to the documentation of this file.
1// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2//
3// JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2016 by Laurent Itti, the University of Southern
4// California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
5//
6// This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
7// redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
8// Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
10// License for more details. You should have received a copy of the GNU General Public License along with this program;
11// if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12//
13// Contact information: Laurent Itti - 3641 Watt Way, HNB-07A - Los Angeles, CA 90089-2520 - USA.
14// Tel: +1 213 740 3527 - itti@pollux.usc.edu - http://iLab.usc.edu - http://jevois.org
15// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16/*! \file */
17
18#include <jevois/Core/Module.H>
20#include <jevois/DNN/Pipeline.H>
21#include <jevois/Util/Utils.H>
22#include <jevois/Debug/Timer.H>
23
24// icon from opencv
25
26static jevois::ParameterCategory const ParamCateg("MultiDNN2 Options");
27
28//! Parameter \relates MultiDNN2
29JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(num, unsigned int, "Number of networks to run and display",
30 4, jevois::Range<unsigned int>(1, 10), ParamCateg);
31
32//! Run multiple neural networks in parallel with an overlapping display
33/*! See \jvmod{DNN} for more details about the JeVois DNN framework.
34
35 Edit the module's \b params.cfg file to select which models to run.
36
37 You can load any model at runtime by setting the \p pipe parameter for each pipeline.
38
39 @author Laurent Itti
40
41 @displayname MultiDNN2
42 @videomapping NONE 0 0 0.0 YUYV 640 480 15.0 JeVois MultiDNN2
43 @videomapping YUYV 640 498 15.0 YUYV 640 480 15.0 JeVois MultiDNN2
44 @email itti\@usc.edu
45 @address University of Southern California, HNB-07A, 3641 Watt Way, Los Angeles, CA 90089-2520, USA
46 @copyright Copyright (C) 2018 by Laurent Itti, iLab and the University of Southern California
47 @mainurl http://jevois.org
48 @supporturl http://jevois.org/doc
49 @otherurl http://iLab.usc.edu
50 @license GPL v3
51 @distribution Unrestricted
52 @restrictions None
53 \ingroup modules */
55 public jevois::Parameter<num>
56{
57 public:
58 // ####################################################################################################
59 //! Constructor
60 // ####################################################################################################
61 using StdModule::StdModule;
62
63 // ####################################################################################################
64 //! Virtual destructor for safe inheritance
65 // ####################################################################################################
66 virtual ~MultiDNN2()
67 { }
68
69 // ####################################################################################################
70 //! Processing function implementation
71 // ####################################################################################################
72 void doprocess(jevois::InputFrame const & inframe, jevois::RawImage * outimg,
73 jevois::OptGUIhelper * helper, bool idle)
74 {
75 // If we have a second (scaled) image, assume this is the one we want to process:
76 jevois::RawImage const inimg = inframe.getp();
77
78 // Loop over all pipelines and run and display each:
79 for (auto & pipe : itsPipes) pipe->process(inimg, this, outimg, helper, idle);
80 }
81
82 // ####################################################################################################
83 //! Processing function, no video output
84 // ####################################################################################################
85 virtual void process(jevois::InputFrame && inframe) override
86 {
87 doprocess(inframe, nullptr, nullptr, false);
88 }
89
90 // ####################################################################################################
91 //! Processing function with video output to USB
92 // ####################################################################################################
93 virtual void process(jevois::InputFrame && inframe, jevois::OutputFrame && outframe) override
94 {
95 // Get the input frame:
96 jevois::RawImage const & inimg = inframe.get();
97 unsigned int const w = inimg.width, h = inimg.height;
98
99 // Get the output image:
100 jevois::RawImage outimg = outframe.get();
101
102 // Input and output sizes and format must match:
103 outimg.require("output", w, h, inimg.fmt);
104
105 // Copy input to output:
106 jevois::rawimage::paste(inimg, outimg, 0, 0);
107
108 // Process and draw any results (e.g., detected boxes) into outimg:
109 doprocess(inframe, &outimg, nullptr, false);
110
111 // Send the output image with our processing results to the host over USB:
112 outframe.send();
113 }
114
115#ifdef JEVOIS_PRO
116 // ####################################################################################################
117 //! Processing function with zero-copy and GUI on JeVois-Pro
118 // ####################################################################################################
119 virtual void process(jevois::InputFrame && inframe, jevois::GUIhelper & helper) override
120 {
121 // Compute overall frame rate, CPU usage, etc:
122 static jevois::Timer timer("main", 20, LOG_DEBUG);
123 std::string const & fpscpu = timer.stop();
124 timer.start();
125
126 // Start the display frame:
127 unsigned short winw, winh;
128 bool idle = helper.startFrame(winw, winh);
129
130 // Display the camera input frame:
131 int x = 0, y = 0; unsigned short w = 0, h = 0;
132 helper.drawInputFrame("c", inframe, x, y, w, h, true);
133
134 // Process and draw any results (e.g., detected boxes) into GUI:
135 doprocess(inframe, nullptr, &helper, idle);
136
137 // Show overall frame rate and camera and display info:
138 helper.iinfo(inframe, fpscpu, winw, winh);
139
140 // Render the image and GUI:
141 helper.endFrame();
142 }
143#endif
144
145 // ####################################################################################################
146 protected:
147 void onParamChange(num const & JEVOIS_UNUSED_PARAM(param), unsigned int const & newval) override
148 {
149 // Try to preserve as many existing pipes as we can:
150 while (itsPipes.size() < newval)
151 itsPipes.emplace_back(addSubComponent<jevois::dnn::Pipeline>("p"+std::to_string(itsPipes.size())));
152
153 while (newval < itsPipes.size()) { removeSubComponent(itsPipes.back()); itsPipes.pop_back(); }
154 }
155
156 std::vector<std::shared_ptr<jevois::dnn::Pipeline>> itsPipes;
157
158};
159
160// Allow the module to be loaded as a shared object (.so) file:
JEVOIS_REGISTER_MODULE(ArUcoBlob)
#define JEVOIS_UNUSED_PARAM(x)
int h
Run multiple neural networks in parallel with an overlapping display.
Definition MultiDNN2.C:56
std::vector< std::shared_ptr< jevois::dnn::Pipeline > > itsPipes
Definition MultiDNN2.C:156
void doprocess(jevois::InputFrame const &inframe, jevois::RawImage *outimg, jevois::OptGUIhelper *helper, bool idle)
Processing function implementation.
Definition MultiDNN2.C:72
void onParamChange(num const &JEVOIS_UNUSED_PARAM(param), unsigned int const &newval) override
Definition MultiDNN2.C:147
virtual void process(jevois::InputFrame &&inframe, jevois::GUIhelper &helper) override
Processing function with zero-copy and GUI on JeVois-Pro.
Definition MultiDNN2.C:119
virtual void process(jevois::InputFrame &&inframe, jevois::OutputFrame &&outframe) override
Processing function with video output to USB.
Definition MultiDNN2.C:93
JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(num, unsigned int, "Number of networks to run and display", 4, jevois::Range< unsigned int >(1, 10), ParamCateg)
Parameter.
virtual ~MultiDNN2()
Virtual destructor for safe inheritance.
Definition MultiDNN2.C:66
virtual void process(jevois::InputFrame &&inframe) override
Processing function, no video output.
Definition MultiDNN2.C:85
void removeSubComponent(std::shared_ptr< Comp > &component)
void drawInputFrame(char const *name, InputFrame const &frame, int &x, int &y, unsigned short &w, unsigned short &h, bool noalias=false, bool casync=false)
bool startFrame(unsigned short &w, unsigned short &h)
void iinfo(jevois::InputFrame const &inframe, std::string const &fpscpu, unsigned short winw=0, unsigned short winh=0)
RawImage const & getp(bool casync=false) const
unsigned int fmt
unsigned int width
unsigned int height
void require(char const *info, unsigned int w, unsigned int h, unsigned int f) const
std::string const & stop(double *seconds)
void paste(RawImage const &src, RawImage &dest, int dx, int dy)