JeVois  1.22
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
Loading...
Searching...
No Matches
Module.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>
19#include <jevois/Core/Engine.H>
23
24#include <opencv2/imgproc/imgproc.hpp>
25
26#include <cmath>
27#include <sstream>
28#include <iomanip>
29
30// ####################################################################################################
31jevois::Module::Module(std::string const & instance) :
32 jevois::Component(instance)
33{ }
34
35// ####################################################################################################
38
39// ####################################################################################################
41{ LFATAL("Not implemented in this module"); }
42
43// ####################################################################################################
45{ LFATAL("Not implemented in this module"); }
46
47#ifdef JEVOIS_PRO
48// ####################################################################################################
50{ LFATAL("Not implemented in this module, and only available on JeVois-Pro"); }
51#endif
52
53// ####################################################################################################
54void jevois::Module::sendSerial(std::string const & str)
55{
56 jevois::Engine * e = dynamic_cast<jevois::Engine *>(itsParent);
57 if (e == nullptr) LFATAL("My parent is not Engine -- CANNOT SEND SERIAL");
58
59 e->sendSerial(str);
60}
61
62// ####################################################################################################
63void jevois::Module::parseSerial(std::string const & str, std::shared_ptr<jevois::UserInterface>)
64{ throw std::runtime_error("Unsupported command [" + str + ']'); }
65
66// ####################################################################################################
67void jevois::Module::supportedCommands(std::ostream & os)
68{ os << "None" << std::endl; }
69
70// ####################################################################################################
71// ####################################################################################################
72jevois::StdModule::StdModule(std::string const & instance) :
73 jevois::Module(instance)
74{ }
75
76// ####################################################################################################
79
80// ####################################################################################################
81std::string jevois::StdModule::getStamp() const
82{
83 std::string ret;
84
85 switch(serstamp::get())
86 {
87 case jevois::modul::SerStamp::None:
88 break;
89
90 case jevois::modul::SerStamp::Frame:
91 ret = std::to_string(frameNum());
92 break;
93
94 case jevois::modul::SerStamp::Time:
95 {
96 std::time_t t = std::time(nullptr); char str[100];
97 std::strftime(str, sizeof(str), "%T", std::localtime(&t));
98 ret = std::string(str);
99 }
100 break;
101
102 case jevois::modul::SerStamp::FrameTime:
103 {
104 std::time_t t = std::time(nullptr); char str[100];
105 std::strftime(str, sizeof(str), "%T", std::localtime(&t));
106 ret = std::to_string(frameNum()) + '/' + std::string(str);
107 }
108 break;
109
110 case jevois::modul::SerStamp::FrameDateTime:
111 {
112 std::time_t t = std::time(nullptr); char str[100];
113 std::strftime(str, sizeof(str), "%F/%T", std::localtime(&t));
114 ret = std::to_string(frameNum()) + '/' + std::string(str);
115 }
116 break;
117 }
118
119 if (ret.empty() == false) ret += ' ';
120 return ret;
121}
122
123// ####################################################################################################
124void jevois::StdModule::sendSerialImg1Dx(unsigned int camw, float x, float size, std::string const & id,
125 std::string const & extra)
126{
127 // Normalize the coordinate and size using the given precision to do rounding:
128 float const eps = std::pow(10.0F, -float(serprec::get()));
129
130 jevois::coords::imgToStdX(x, camw, eps);
131 float dummy = 0.0F; jevois::coords::imgToStdSize(size, dummy, camw, 100, eps);
132
133 // Delegate:
134 sendSerialStd1Dx(x, size, id, extra);
135}
136
137// ####################################################################################################
138void jevois::StdModule::sendSerialStd1Dx(float x, float size, std::string const & id, std::string const & extra)
139{
140 // Build the message depending on desired style:
141 std::ostringstream oss; oss << std::fixed << std::setprecision(serprec::get());
142
143 // Prepend frame/date/time as possibly requested by parameter serstamp:
144 oss << getStamp();
145
146 // Format the message depending on parameter serstyle:
147 switch (serstyle::get())
148 {
149 case jevois::modul::SerStyle::Terse:
150 oss << "T1 " << x;
151 break;
152
153 case jevois::modul::SerStyle::Normal:
154 oss << "N1 ";
155 if (id.empty()) oss << "unknown "; else oss << jevois::replaceWhitespace(id) << ' ';
156 oss << x << ' ' << size;
157 break;
158
159 case jevois::modul::SerStyle::Detail:
160 case jevois::modul::SerStyle::Fine:
161 oss << "D1 ";
162 if (id.empty()) oss << "unknown "; else oss << jevois::replaceWhitespace(id) << ' ';
163 oss << x - 0.5F * size << ' ' << x + 0.5F * size;
164 if (extra.empty() == false) oss << ' ' << extra;
165 break;
166 }
167
168 // Send the message:
169 sendSerial(oss.str());
170}
171
172// ####################################################################################################
173void jevois::StdModule::sendSerialImg1Dy(unsigned int camh, float y, float size, std::string const & id,
174 std::string const & extra)
175{
176 // Normalize the coordinate and size using the given precision to do rounding:
177 float const eps = std::pow(10.0F, -float(serprec::get()));
178 jevois::coords::imgToStdY(y, camh, eps);
179 float dummy = 0.0F; jevois::coords::imgToStdSize(dummy, size, 100, camh, eps);
180
181 // Delegate:
182 sendSerialStd1Dy(y, size, id, extra);
183}
184
185// ####################################################################################################
186void jevois::StdModule::sendSerialStd1Dy(float y, float size, std::string const & id, std::string const & extra)
187{
188 // Build the message depending on desired style:
189 std::ostringstream oss; oss << std::fixed << std::setprecision(serprec::get());
190
191 // Prepend frame/date/time as possibly requested by parameter serstamp:
192 oss << getStamp();
193
194 // Format the message depending on parameter serstyle:
195 switch (serstyle::get())
196 {
197 case jevois::modul::SerStyle::Terse:
198 oss << "T1 " << y;
199 break;
200
201 case jevois::modul::SerStyle::Normal:
202 oss << "N1 ";
203 if (id.empty()) oss << "unknown "; else oss << jevois::replaceWhitespace(id) << ' ';
204 oss << y << ' ' << size;
205 break;
206
207 case jevois::modul::SerStyle::Detail:
208 case jevois::modul::SerStyle::Fine:
209 oss << "D1 ";
210 if (id.empty()) oss << "unknown "; else oss << jevois::replaceWhitespace(id) << ' ';
211 oss << y - 0.5F * size << ' ' << y + 0.5F * size;
212 if (extra.empty() == false) oss << ' ' << extra;
213 break;
214 }
215
216 // Send the message:
217 sendSerial(oss.str());
218}
219
220// ####################################################################################################
221void jevois::StdModule::sendSerialImg2D(unsigned int camw, unsigned int camh, float x, float y, float w, float h,
222 std::string const & id, std::string const & extra)
223{
224 // Normalize the coordinates and sizes using the given precision to do rounding:
225 float const eps = std::pow(10.0F, -float(serprec::get()));
226
227 jevois::coords::imgToStd(x, y, camw, camh, eps);
228 jevois::coords::imgToStdSize(w, h, camw, camh, eps);
229
230 // Delegate:
231 sendSerialStd2D(x, y, w, h, id, extra);
232}
233// ####################################################################################################
234void jevois::StdModule::sendSerialStd2D(float x, float y, float w, float h, std::string const & id,
235 std::string const & extra)
236{
237 // Build the message depending on desired style:
238 std::ostringstream oss; oss << std::fixed << std::setprecision(serprec::get());
239
240 // Prepend frame/date/time as possibly requested by parameter serstamp:
241 oss << getStamp();
242
243 // Format the message depending on parameter serstyle:
244 switch (serstyle::get())
245 {
246 case jevois::modul::SerStyle::Terse:
247 oss << "T2 " << x << ' ' << y;
248 break;
249
250 case jevois::modul::SerStyle::Normal:
251 oss << "N2 ";
252 if (id.empty()) oss << "unknown "; else oss << jevois::replaceWhitespace(id) << ' ';
253 oss << x << ' ' << y << ' ' << w << ' ' << h;
254 break;
255
256 case jevois::modul::SerStyle::Detail:
257 oss << "D2 ";
258 if (id.empty()) oss << "unknown "; else oss << jevois::replaceWhitespace(id) << ' ';
259 oss << x - 0.5F * w << ' ' << y - 0.5F * h << ' ';
260 oss << x + 0.5F * w << ' ' << y - 0.5F * h << ' ';
261 oss << x + 0.5F * w << ' ' << y + 0.5F * h << ' ';
262 oss << x + 0.5F * w << ' ' << y - 0.5F * h;
263 if (extra.empty() == false) oss << ' ' << extra;
264 break;
265
266 case jevois::modul::SerStyle::Fine:
267 oss << "F2 ";
268 if (id.empty()) oss << "unknown "; else oss << jevois::replaceWhitespace(id) << ' ';
269 oss << 4 << ' '; // number of vertices
270 oss << x - 0.5F * w << ' ' << y - 0.5F * h << ' ';
271 oss << x + 0.5F * w << ' ' << y - 0.5F * h << ' ';
272 oss << x + 0.5F * w << ' ' << y + 0.5F * h << ' ';
273 oss << x + 0.5F * w << ' ' << y - 0.5F * h;
274 if (extra.empty() == false) oss << ' ' << extra;
275 break;
276 }
277
278 // Send the message:
279 sendSerial(oss.str());
280}
281
282// ####################################################################################################
283template <typename T>
284void jevois::StdModule::sendSerialContour2D(unsigned int camw, unsigned int camh, std::vector<cv::Point_<T> > points,
285 std::string const & id, std::string const & extra)
286{
287 // Format the message depending on parameter serstyle:
288 switch (serstyle::get())
289 {
290 case jevois::modul::SerStyle::Terse:
291 {
292 // Compute center of gravity:
293 float cx = 0.0F, cy = 0.0F;
294 for (cv::Point2f const p : points) { cx += p.x; cy += p.y; }
295 if (points.size()) { cx /= points.size(); cy /= points.size(); }
296 sendSerialImg2D(camw, camh, cx, cy, 0.0F, 0.0F, id, extra);
297 }
298 break;
299
300 case jevois::modul::SerStyle::Normal:
301 {
302 // Compute upright bounding rectangle:
303 cv::Rect r = cv::boundingRect(points);
304 sendSerialImg2D(camw, camh, r.x + 0.5F * r.width, r.y + 0.5F * r.height, r.width, r.height, id, extra);
305 }
306 break;
307
308 case jevois::modul::SerStyle::Detail:
309 {
310 // Compute minimal rotated rectangle enclosing the points:
311 cv::RotatedRect r = cv::minAreaRect(points);
312
313 // Build the message:
314 unsigned int const prec = serprec::get(); float const eps = std::pow(10.0F, -float(prec));
315 std::ostringstream oss; oss << std::fixed << std::setprecision(prec);
316
317 // Prepend frame/date/time as possibly requested by parameter serstamp:
318 oss << getStamp();
319
320 // Now the rest of the message:
321 oss << "D2 ";
322 if (id.empty()) oss << "unknown "; else oss << jevois::replaceWhitespace(id) << ' ';
323 cv::Point2f corners[4];
324 r.points(corners);
325
326 oss << 4; // number of vertices
327
328 for (int i = 0; i < 4; ++i)
329 {
330 float x = corners[i].x, y = corners[i].y;
331 jevois::coords::imgToStd(x, y, camw, camh, eps);
332 oss << ' ' << x << ' ' << y;
333 }
334 if (extra.empty() == false) oss << ' ' << extra;
335
336 // Send the message:
337 sendSerial(oss.str());
338 }
339 break;
340
341 case jevois::modul::SerStyle::Fine:
342 {
343 // Build the message:
344 unsigned int const prec = serprec::get(); float const eps = std::pow(10.0F, -float(prec));
345 std::ostringstream oss; oss << std::fixed << std::setprecision(prec);
346
347 // Prepend frame/date/time as possibly requested by parameter serstamp:
348 oss << getStamp();
349
350 // Now the rest of the message:
351 oss << "F2 ";
352 if (id.empty()) oss << "unknown "; else oss << jevois::replaceWhitespace(id) << ' ';
353 oss << points.size(); // number of vertices
354
355 for (cv::Point2f const p : points)
356 {
357 float x = p.x, y = p.y;
358 jevois::coords::imgToStd(x, y, camw, camh, eps);
359 oss << ' ' << x << ' ' << y;
360 }
361 if (extra.empty() == false) oss << ' ' << extra;
362
363 // Send the message:
364 sendSerial(oss.str());
365 }
366 break;
367 }
368}
369
370// Compile in explicit template instantiations:
371namespace jevois
372{
373 template
374 void StdModule::sendSerialContour2D(unsigned int camw, unsigned int camh, std::vector<cv::Point_<int> > points,
375 std::string const & id, std::string const & extra);
376 template
377 void StdModule::sendSerialContour2D(unsigned int camw, unsigned int camh, std::vector<cv::Point_<float> > points,
378 std::string const & id, std::string const & extra);
379 template
380 void StdModule::sendSerialContour2D(unsigned int camw, unsigned int camh, std::vector<cv::Point_<double> > points,
381 std::string const & id, std::string const & extra);
382}
383
384// ####################################################################################################
385void jevois::StdModule::sendSerialStd3D(float x, float y, float z, float w, float h, float d,
386 float q1, float q2, float q3, float q4,
387 std::string const & id, std::string const & extra)
388{
389 // Build the message depending on desired style:
390 std::ostringstream oss; oss << std::fixed << std::setprecision(serprec::get());
391
392 // Prepend frame/date/time as possibly requested by parameter serstamp:
393 oss << getStamp();
394
395 // Format the message depending on parameter serstyle:
396 switch (serstyle::get())
397 {
398 case jevois::modul::SerStyle::Terse:
399 oss << "T3 " << x << ' ' << y << ' ' << z;
400 break;
401
402 case jevois::modul::SerStyle::Normal:
403 oss << "N3 ";
404 if (id.empty()) oss << "unknown "; else oss << jevois::replaceWhitespace(id) << ' ';
405 oss << x << ' ' << y << ' ' << z << ' ' << w << ' ' << h << ' ' << d;
406 break;
407
408 case jevois::modul::SerStyle::Detail:
409 oss << "D3 ";
410 if (id.empty()) oss << "unknown "; else oss << jevois::replaceWhitespace(id) << ' ';
411 oss << x << ' ' << y << ' ' << z << ' ' << w << ' ' << h << ' ' << d << ' '
412 << q1 << ' ' << q2 << ' ' << q3 << ' ' << q4;
413 if (extra.empty() == false) oss << ' ' << extra;
414 break;
415
416 case jevois::modul::SerStyle::Fine:
417 oss << "F3 ";
418 if (id.empty()) oss << "unknown "; else oss << jevois::replaceWhitespace(id) << ' ';
419 oss << 8 << ' '; // number of vertices
420 oss << x - 0.5F * w << ' ' << y - 0.5F * h << ' ' << z - 0.5F * d << ' ';
421 oss << x + 0.5F * w << ' ' << y - 0.5F * h << ' ' << z - 0.5F * d << ' ';
422 oss << x + 0.5F * w << ' ' << y + 0.5F * h << ' ' << z - 0.5F * d << ' ';
423 oss << x + 0.5F * w << ' ' << y - 0.5F * h << ' ' << z - 0.5F * d << ' ';
424 oss << x - 0.5F * w << ' ' << y - 0.5F * h << ' ' << z + 0.5F * d << ' ';
425 oss << x + 0.5F * w << ' ' << y - 0.5F * h << ' ' << z + 0.5F * d << ' ';
426 oss << x + 0.5F * w << ' ' << y + 0.5F * h << ' ' << z + 0.5F * d << ' ';
427 oss << x + 0.5F * w << ' ' << y - 0.5F * h << ' ' << z + 0.5F * d << ' ';
428 if (extra.empty() == false) oss << ' ' << extra;
429 break;
430 }
431
432 // Send the message:
433 sendSerial(oss.str());
434}
435
436// ####################################################################################################
437void jevois::StdModule::sendSerialStd3D(std::vector<cv::Point3f> points, std::string const & id,
438 std::string const & extra)
439{
440 // Format the message depending on parameter serstyle:
441 switch (serstyle::get())
442 {
443 case jevois::modul::SerStyle::Terse:
444 {
445 // Compute center of gravity:
446 cv::Point3f cg(0.0F, 0.0F, 0.0F);
447 for (cv::Point3f const & p : points) cg += p;
448 if (points.size()) { cg.x /= points.size(); cg.y /= points.size(); cg.z /= points.size(); }
449 sendSerialStd3D(cg.x, cg.y, cg.z, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, id, extra);
450 }
451 break;
452
453 case jevois::modul::SerStyle::Normal:
454 {
455 // Compute upright bounding parallelepiped:
456 cv::Point3f cg(0.0F, 0.0F, 0.0F), pmin(1e30F, 1e30F, 1e30F), pmax(-1e30F, -1e30F, -1e30F);
457 for (cv::Point3f const & p : points)
458 {
459 cg += p;
460 if (p.x < pmin.x) pmin.x = p.x;
461 if (p.y < pmin.y) pmin.y = p.y;
462 if (p.z < pmin.z) pmin.z = p.z;
463 if (p.x > pmax.x) pmax.x = p.x;
464 if (p.y > pmax.y) pmax.y = p.y;
465 if (p.z > pmax.z) pmax.z = p.z;
466 }
467 if (points.size()) { cg.x /= points.size(); cg.y /= points.size(); cg.z /= points.size(); }
468 sendSerialStd3D(cg.x, cg.y, cg.z, pmax.x - pmin.x, pmax.y - pmin.y, pmax.z - pmin.z, 0.0F, 0.0F, 0.0F, 0.0F,
469 id, extra);
470 }
471 break;
472
473 case jevois::modul::SerStyle::Detail:
474 {
475 // Compute upright bounding parallelepiped:
476 cv::Point3f cg(0.0F, 0.0F, 0.0F), pmin(1e30F, 1e30F, 1e30F), pmax(-1e30F, -1e30F, -1e30F);
477 for (cv::Point3f const & p : points)
478 {
479 cg += p;
480 if (p.x < pmin.x) pmin.x = p.x;
481 if (p.y < pmin.y) pmin.y = p.y;
482 if (p.z < pmin.z) pmin.z = p.z;
483 if (p.x > pmax.x) pmax.x = p.x;
484 if (p.y > pmax.y) pmax.y = p.y;
485 if (p.z > pmax.z) pmax.z = p.z;
486 }
487 if (points.size()) { cg.x /= points.size(); cg.y /= points.size(); cg.z /= points.size(); }
488 // FIXME what should we send for the quaternion?
489 sendSerialStd3D(cg.x, cg.y, cg.z, pmax.x - pmin.x, pmax.y - pmin.y, pmax.z - pmin.z, 0.0F, 0.0F, 0.0F, 1.0F,
490 id, extra);
491 }
492 break;
493
494 case jevois::modul::SerStyle::Fine:
495 {
496 // Build the message:
497 unsigned int const prec = serprec::get();
498 std::ostringstream oss; oss << std::fixed << std::setprecision(prec);
499
500 // Prepend frame/date/time as possibly requested by parameter serstamp:
501 oss << getStamp();
502
503 // Now the rest of the message:
504 oss << "F3 ";
505 if (id.empty()) oss << "unknown "; else oss << jevois::replaceWhitespace(id) << ' ';
506 oss << points.size(); // number of vertices
507
508 for (cv::Point3f const & p : points) oss << ' ' << p.x << ' ' << p.y << ' ' << p.z;
509 if (extra.empty() == false) oss << ' ' << extra;
510
511 // Send the message:
512 sendSerial(oss.str());
513 }
514 break;
515 }
516}
517
518// ####################################################################################################
520{
521 jevois::modul::SerMark const m = sermark::get();
522 if (m == jevois::modul::SerMark::None || m == jevois::modul::SerMark::Stop) return;
523 sendSerial(getStamp() + "MARK START");
524}
525
526// ####################################################################################################
528{
529 jevois::modul::SerMark const m = sermark::get();
530 if (m == jevois::modul::SerMark::None || m == jevois::modul::SerMark::Start) return;
531 sendSerial(getStamp() + "MARK STOP");
532}
533
534// ####################################################################################################
535void jevois::StdModule::sendSerialObjReco(std::vector<jevois::ObjReco> const & res)
536{
537 if (res.empty()) return;
538
539 // Build the message depending on desired style:
540 std::ostringstream oss; oss << std::fixed << std::setprecision(serprec::get());
541
542 // Prepend frame/date/time as possibly requested by parameter serstamp:
543 oss << getStamp();
544
545 // Format the message depending on parameter serstyle:
546 switch (serstyle::get())
547 {
548 case jevois::modul::SerStyle::Terse:
549 oss << "TO " << jevois::replaceWhitespace(res[0].category);
550 break;
551
552 case jevois::modul::SerStyle::Normal:
553 oss << "NO " << jevois::replaceWhitespace(res[0].category) << ':' << res[0].score;
554 break;
555
556 case jevois::modul::SerStyle::Detail:
557 oss << "DO";
558 for (auto const & r : res) oss << ' ' << jevois::replaceWhitespace(r.category) << ':' << r.score;
559 break;
560
561 case jevois::modul::SerStyle::Fine:
562 oss << "FO";
563 for (auto const & r : res) oss << ' ' << jevois::replaceWhitespace(r.category) << ':' << r.score;
564 break;
565 }
566
567 // Send the message:
568 sendSerial(oss.str());
569}
570
571// ####################################################################################################
572void jevois::StdModule::sendSerialObjDetImg2D(unsigned int camw, unsigned int camh, float x, float y, float w, float h,
573 std::vector<ObjReco> const & res)
574{
575 if (res.empty()) return;
576
577 std::string best, extra; std::string * ptr = &best;
578 std::string fmt = "%s:%." + std::to_string(serprec::get()) + "f";
579
580 for (auto const & r : res)
581 {
582 switch (serstyle::get())
583 {
584 case jevois::modul::SerStyle::Terse:
585 (*ptr) += jevois::replaceWhitespace(r.category);
586 break;
587
588 default:
589 (*ptr) += jevois::sformat(fmt.c_str(), jevois::replaceWhitespace(r.category).c_str(), r.score);
590 }
591 if (ptr == &extra) (*ptr) += ' ';
592 ptr = &extra;
593 }
594
595 // Remove last space:
596 if (extra.empty() == false) extra = extra.substr(0, extra.length() - 1);
597
598 sendSerialImg2D(camw, camh, x, y, w, h, best, extra);
599}
600
601// ####################################################################################################
602void jevois::StdModule::sendSerialObjDetImg2D(unsigned int camw, unsigned int camh, jevois::ObjDetect const & det)
603{
604 sendSerialObjDetImg2D(camw, camh, det.tlx, det.tly, det.brx - det.tlx, det.bry - det.tly, det.reco);
605}
606
607// ####################################################################################################
608void jevois::StdModule::sendSerialObjDetImg2D(unsigned int camw, unsigned int camh, jevois::ObjDetectOBB const & det)
609{
610 std::vector<jevois::ObjReco> const & res = det.reco;
611 if (res.empty()) return;
612
613 std::string best, extra; std::string * ptr = &best;
614 std::string fmt = "%s:%." + std::to_string(serprec::get()) + "f";
615
616 for (auto const & r : res)
617 {
618 switch (serstyle::get())
619 {
620 case jevois::modul::SerStyle::Terse:
621 (*ptr) += jevois::replaceWhitespace(r.category);
622 break;
623
624 default:
625 (*ptr) += jevois::sformat(fmt.c_str(), jevois::replaceWhitespace(r.category).c_str(), r.score);
626 }
627 if (ptr == &extra) (*ptr) += ' ';
628 ptr = &extra;
629 }
630
631 // Remove last space:
632 if (extra.empty() == false) extra = extra.substr(0, extra.length() - 1);
633
634 std::vector<cv::Point2f> pts; det.rect.points(pts);
635 sendSerialContour2D(camw, camh, pts, best, extra);
636}
637
int h
Definition GUIhelper.C:2520
A component of a model hierarchy.
Definition Component.H:182
friend class Module
Definition Component.H:515
JeVois processing engine - gets images from camera sensor, processes them, and sends results over USB...
Definition Engine.H:416
void sendSerial(std::string const &str, bool islog=false)
Send a string to all serial ports.
Definition Engine.C:1356
Helper class to assist modules in creating graphical and GUI elements.
Definition GUIhelper.H:133
Exception-safe wrapper around a raw camera input frame.
Definition InputFrame.H:51
Virtual base class for a vision processing module.
Definition Module.H:105
virtual void sendSerial(std::string const &str)
Send a string over the 'serout' serial port.
Definition Module.C:54
virtual void supportedCommands(std::ostream &os)
Human-readable description of this Module's supported custom commands.
Definition Module.C:67
virtual void parseSerial(std::string const &str, std::shared_ptr< UserInterface > s)
Receive a string from a serial port which contains a user command.
Definition Module.C:63
virtual ~Module()
Virtual destructor for safe inheritance.
Definition Module.C:36
virtual void process(InputFrame &&inframe, OutputFrame &&outframe)
Processing function, version that receives a frame from camera and sends a frame out over USB.
Definition Module.C:40
Exception-safe wrapper around a raw image to be sent over USB.
Definition OutputFrame.H:53
void sendSerialStd1Dx(float x, float size=0.0F, std::string const &id="", std::string const &extra="")
Send standardized 1D message for a standardized X coordinate.
Definition Module.C:138
void sendSerialObjDetImg2D(unsigned int camw, unsigned int camh, float x, float y, float w, float h, std::vector< ObjReco > const &res)
Send a standardized object detection + recognition message.
Definition Module.C:572
virtual ~StdModule()
Virtual destructor for safe inheritance.
Definition Module.C:77
std::string getStamp() const
Get a string with the frame/date/time stamp in it, depending on serstamp parameter.
Definition Module.C:81
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="")
Send standardized 3D message.
Definition Module.C:385
void sendSerialObjReco(std::vector< ObjReco > const &res)
Send a standardized object recognition message.
Definition Module.C:535
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="")
Send standardized 2D message for image coordinates.
Definition Module.C:221
void sendSerialStd1Dy(float y, float size=0.0F, std::string const &id="", std::string const &extra="")
Send standardized 1D message for a standardized Y coordinate.
Definition Module.C:186
void sendSerialMarkStop()
Send a message MARK STOP to indicate the end of processing.
Definition Module.C:527
StdModule(std::string const &instance)
Constructor.
Definition Module.C:72
void sendSerialStd2D(float x, float y, float w=0.0F, float h=0.0F, std::string const &id="", std::string const &extra="")
Send standardized 2D message for standardized coordinates.
Definition Module.C:234
void sendSerialImg1Dx(unsigned int camw, float x, float size=0.0F, std::string const &id="", std::string const &extra="")
Send standardized 1D message for an X image coordinate.
Definition Module.C:124
void sendSerialImg1Dy(unsigned int camh, float y, float size=0.0F, std::string const &id="", std::string const &extra="")
Send standardized 1D message for an Y image coordinate.
Definition Module.C:173
void sendSerialMarkStart()
Send a message MARK START to indicate the beginning of processing.
Definition Module.C:519
void sendSerialContour2D(unsigned int camw, unsigned int camh, std::vector< cv::Point_< T > > points, std::string const &id="", std::string const &extra="")
Send standardized 2D message for polygons in image coordinates.
Definition Module.C:284
void imgToStdX(float &x, unsigned int const width, float const eps=0.1F)
Transform X coordinate in-place from camera to standardized, using given image width and height.
Definition Coordinates.C:36
void imgToStdY(float &y, unsigned int const height, float const eps=0.1F)
Transform Y coordinate in-place from camera to standardized, using given image width and height.
Definition Coordinates.C:43
void imgToStd(float &x, float &y, RawImage const &camimg, float const eps=0.1F)
Transform coordinates in-place from camera to standardized, using a RawImage to establish image size.
Definition Coordinates.C:22
void imgToStdSize(float &w, float &h, unsigned int const width, unsigned int const height, float const eps=0.1F)
Transform size in-place from camera to standardized, using given image width and height.
Definition Coordinates.C:50
#define LFATAL(msg)
Convenience macro for users to print out console or syslog messages, FATAL level.
Definition Log.H:230
std::string sformat(char const *fmt,...) __attribute__((format(__printf__
Create a string using printf style arguments.
Definition Utils.C:440
std::string replaceWhitespace(std::string const &str, char rep='_')
Replace white space characters in a string with underscore (default) or another character.
Definition Utils.C:301
Main namespace for all JeVois classes and functions.
Definition Concepts.dox:2
A trivial struct to store object detection results, for oriented bounding boxes (OBB)
Definition ObjDetect.H:38
std::vector< ObjReco > reco
Recognized classes with their scores.
Definition ObjDetect.H:40
cv::RotatedRect rect
Oriented bounding box.
Definition ObjDetect.H:39
A trivial struct to store object detection results, for standard (straight up) bounding boxes.
Definition ObjDetect.H:29
int bry
Bounding box.
Definition ObjDetect.H:30
std::vector< ObjReco > reco
Recognized classes with their scores.
Definition ObjDetect.H:31