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