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