JeVois  1.5
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/VideoInput.H>
21 #include <jevois/Core/Engine.H>
25 
26 #include <opencv2/imgproc/imgproc.hpp>
27 
28 #include <cmath>
29 #include <sstream>
30 #include <iomanip>
31 
32 // ####################################################################################################
33 jevois::InputFrame::InputFrame(std::shared_ptr<jevois::VideoInput> const & cam, bool turbo) :
34  itsCamera(cam), itsDidGet(false), itsDidDone(false), itsTurbo(turbo)
35 { }
36 
37 // ####################################################################################################
39 {
40  // If itsCamera is invalidated, we have been moved to another object, so do not do anything here:
41  if (itsCamera.get() == nullptr) return;
42 
43  // If we did not yet get(), just end now, camera will drop this frame:
44  if (itsDidGet == false) return;
45 
46  // If we did get() but not done(), signal done now:
47  if (itsDidDone == false) try { itsCamera->done(itsImage); } catch (...) { }
48 }
49 
50 // ####################################################################################################
51 jevois::RawImage const & jevois::InputFrame::get(bool casync) const
52 {
53  itsCamera->get(itsImage);
54  itsDidGet = true;
55  if (casync && itsTurbo) itsImage.buf->sync();
56  return itsImage;
57 }
58 
59 // ####################################################################################################
61 {
62  itsCamera->done(itsImage);
63  itsDidDone = true;
64 }
65 
66 // ####################################################################################################
67 cv::Mat jevois::InputFrame::getCvGRAY(bool casync) const
68 {
69  jevois::RawImage const & rawimg = get(casync);
70  cv::Mat cvimg = jevois::rawimage::convertToCvGray(rawimg);
71  done();
72  return cvimg;
73 }
74 
75 // ####################################################################################################
76 cv::Mat jevois::InputFrame::getCvBGR(bool casync) const
77 {
78  jevois::RawImage const & rawimg = get(casync);
79  cv::Mat cvimg = jevois::rawimage::convertToCvBGR(rawimg);
80  done();
81  return cvimg;
82 }
83 
84 // ####################################################################################################
85 cv::Mat jevois::InputFrame::getCvRGB(bool casync) const
86 {
87  jevois::RawImage const & rawimg = get(casync);
88  cv::Mat cvimg = jevois::rawimage::convertToCvRGB(rawimg);
89  done();
90  return cvimg;
91 }
92 
93 // ####################################################################################################
94 cv::Mat jevois::InputFrame::getCvRGBA(bool casync) const
95 {
96  jevois::RawImage const & rawimg = get(casync);
97  cv::Mat cvimg = jevois::rawimage::convertToCvRGBA(rawimg);
98  done();
99  return cvimg;
100 }
101 
102 // ####################################################################################################
103 // ####################################################################################################
104 jevois::OutputFrame::OutputFrame(std::shared_ptr<jevois::VideoOutput> const & gad, jevois::RawImage * excimg) :
105  itsGadget(gad), itsDidGet(false), itsDidSend(false), itsImagePtrForException(excimg)
106 { }
107 
108 // ####################################################################################################
110 {
111  // If itsGadget is invalidated, we have been moved to another object, so do not do anything here:
112  if (itsGadget.get() == nullptr) return;
113 
114  // If we did not get(), just end now:
115  if (itsDidGet == false) return;
116 
117  // If Engine gave us a non-zero image pointer for exceptions, and we did get(), pass down the buffer we did get, so
118  // that Engine can write exception text into it, unless it is too late (exception occurred after send()) or too early
119  // (before get()), in which case Engine will get its own buffer:
120  if (itsImagePtrForException)
121  {
122  if (itsDidSend == false) { *itsImagePtrForException = itsImage; }
123  // Engine will be responsible for the final send()
124  }
125  else
126  {
127  // If we did get() but not send(), send now (the image will likely contain garbage):
128  if (itsDidSend == false) try { itsGadget->send(itsImage); } catch (...) { }
129  }
130 }
131 
132 // ####################################################################################################
134 {
135  itsGadget->get(itsImage);
136  itsDidGet = true;
137  return itsImage;
138 }
139 
140 // ####################################################################################################
142 {
143  itsGadget->send(itsImage);
144  itsDidSend = true;
145  if (itsImagePtrForException) itsImagePtrForException->invalidate();
146 }
147 
148 // ####################################################################################################
149 void jevois::OutputFrame::sendCvGRAY(cv::Mat const & img, int quality) const
150 {
151  jevois::RawImage rawimg = get();
152  jevois::rawimage::convertCvGRAYtoRawImage(img, rawimg, quality);
153  send();
154 }
155 
156 // ####################################################################################################
157 void jevois::OutputFrame::sendCvBGR(cv::Mat const & img, int quality) const
158 {
159  jevois::RawImage rawimg = get();
160  jevois::rawimage::convertCvBGRtoRawImage(img, rawimg, quality);
161  send();
162 }
163 // ####################################################################################################
164 void jevois::OutputFrame::sendCvRGB(cv::Mat const & img, int quality) const
165 {
166  jevois::RawImage rawimg = get();
167  jevois::rawimage::convertCvRGBtoRawImage(img, rawimg, quality);
168  send();
169 }
170 
171 // ####################################################################################################
172 void jevois::OutputFrame::sendCvRGBA(cv::Mat const & img, int quality) const
173 {
174  jevois::RawImage rawimg = get();
175  jevois::rawimage::convertCvRGBAtoRawImage(img, rawimg, quality);
176  send();
177 }
178 
179 // ####################################################################################################
180 // ####################################################################################################
181 jevois::Module::Module(std::string const & instance) :
182  jevois::Component(instance)
183 { }
184 
185 // ####################################################################################################
187 { }
188 
189 // ####################################################################################################
190 void jevois::Module::process(InputFrame && JEVOIS_UNUSED_PARAM(inframe), OutputFrame && JEVOIS_UNUSED_PARAM(outframe))
191 { LFATAL("Not implemented in this module"); }
192 
193 // ####################################################################################################
194 void jevois::Module::process(InputFrame && JEVOIS_UNUSED_PARAM(inframe))
195 { LFATAL("Not implemented in this module"); }
196 
197 // ####################################################################################################
198 void jevois::Module::sendSerial(std::string const & str)
199 {
200  jevois::Engine * e = dynamic_cast<jevois::Engine *>(itsParent);
201  if (e == nullptr) LFATAL("My parent is not Engine -- CANNOT SEND SERIAL");
202 
203  e->sendSerial(str);
204 }
205 
206 // ####################################################################################################
207 void jevois::Module::parseSerial(std::string const & str,
208  std::shared_ptr<jevois::UserInterface> JEVOIS_UNUSED_PARAM(s))
209 { throw std::runtime_error("Unsupported command [" + str + ']'); }
210 
211 // ####################################################################################################
212 void jevois::Module::supportedCommands(std::ostream & os)
213 { os << "None" << std::endl; }
214 
215 // ####################################################################################################
216 // ####################################################################################################
217 jevois::StdModule::StdModule(std::string const & instance) :
218  jevois::Module(instance)
219 { }
220 
221 // ####################################################################################################
223 { }
224 
225 // ####################################################################################################
226 void jevois::StdModule::sendSerialImg1Dx(unsigned int camw, float x, float size, std::string const & id,
227  std::string const & extra)
228 {
229  // Normalize the coordinate and size using the given precision to do rounding:
230  float const eps = std::pow(10.0F, -float(serprec::get()));
231 
232  jevois::coords::imgToStdX(x, camw, eps);
233  float dummy = 0.0F; jevois::coords::imgToStdSize(size, dummy, camw, 100, eps);
234 
235  // Delegate:
236  sendSerialStd1Dx(x, size, id, extra);
237 }
238 
239 // ####################################################################################################
240 void jevois::StdModule::sendSerialStd1Dx(float x, float size, std::string const & id, 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  switch (serstyle::get())
246  {
247  case jevois::module::SerStyle::Terse:
248  oss << "T1 " << x;
249  break;
250 
251  case jevois::module::SerStyle::Normal:
252  oss << "N1 ";
253  if (id.empty()) oss << "unknown "; else oss << jevois::replaceWhitespace(id) << ' ';
254  oss << x << ' ' << size;
255  break;
256 
257  case jevois::module::SerStyle::Detail:
258  case jevois::module::SerStyle::Fine:
259  oss << "D1 ";
260  if (id.empty()) oss << "unknown "; else oss << jevois::replaceWhitespace(id) << ' ';
261  oss << x - 0.5F * size << ' ' << x + 0.5F * size;
262  if (extra.empty() == false) oss << ' ' << extra;
263  break;
264  }
265 
266  // Send the message:
267  sendSerial(oss.str());
268 }
269 
270 // ####################################################################################################
271 void jevois::StdModule::sendSerialImg1Dy(unsigned int camh, float y, float size, std::string const & id,
272  std::string const & extra)
273 {
274  // Normalize the coordinate and size using the given precision to do rounding:
275  float const eps = std::pow(10.0F, -float(serprec::get()));
276  jevois::coords::imgToStdY(y, camh, eps);
277  float dummy = 0.0F; jevois::coords::imgToStdSize(dummy, size, 100, camh, eps);
278 
279  // Delegate:
280  sendSerialStd1Dy(y, size, id, extra);
281 }
282 
283 // ####################################################################################################
284 void jevois::StdModule::sendSerialStd1Dy(float y, float size, std::string const & id, std::string const & extra)
285 {
286  // Build the message depending on desired style:
287  std::ostringstream oss; oss << std::fixed << std::setprecision(serprec::get());
288 
289  switch (serstyle::get())
290  {
291  case jevois::module::SerStyle::Terse:
292  oss << "T1 " << y;
293  break;
294 
295  case jevois::module::SerStyle::Normal:
296  oss << "N1 ";
297  if (id.empty()) oss << "unknown "; else oss << jevois::replaceWhitespace(id) << ' ';
298  oss << y << ' ' << size;
299  break;
300 
301  case jevois::module::SerStyle::Detail:
302  case jevois::module::SerStyle::Fine:
303  oss << "D1 ";
304  if (id.empty()) oss << "unknown "; else oss << jevois::replaceWhitespace(id) << ' ';
305  oss << y - 0.5F * size << ' ' << y + 0.5F * size;
306  if (extra.empty() == false) oss << ' ' << extra;
307  break;
308  }
309 
310  // Send the message:
311  sendSerial(oss.str());
312 }
313 
314 // ####################################################################################################
315 void jevois::StdModule::sendSerialImg2D(unsigned int camw, unsigned int camh, float x, float y, float w, float h,
316  std::string const & id, std::string const & extra)
317 {
318  // Normalize the coordinates and sizes using the given precision to do rounding:
319  float const eps = std::pow(10.0F, -float(serprec::get()));
320 
321  jevois::coords::imgToStd(x, y, camw, camh, eps);
322  jevois::coords::imgToStdSize(w, h, camw, camh, eps);
323 
324  // Delegate:
325  sendSerialStd2D(x, y, w, h, id, extra);
326 }
327 // ####################################################################################################
328 void jevois::StdModule::sendSerialStd2D(float x, float y, float w, float h, std::string const & id,
329  std::string const & extra)
330 {
331  // Build the message depending on desired style:
332  std::ostringstream oss; oss << std::fixed << std::setprecision(serprec::get());
333 
334  switch (serstyle::get())
335  {
336  case jevois::module::SerStyle::Terse:
337  oss << "T2 " << x << ' ' << y;
338  break;
339 
340  case jevois::module::SerStyle::Normal:
341  oss << "N2 ";
342  if (id.empty()) oss << "unknown "; else oss << jevois::replaceWhitespace(id) << ' ';
343  oss << x << ' ' << y << ' ' << w << ' ' << h;
344  break;
345 
346  case jevois::module::SerStyle::Detail:
347  oss << "D2 ";
348  if (id.empty()) oss << "unknown "; else oss << jevois::replaceWhitespace(id) << ' ';
349  oss << x - 0.5F * w << ' ' << y - 0.5F * h << ' ';
350  oss << x + 0.5F * w << ' ' << y - 0.5F * h << ' ';
351  oss << x + 0.5F * w << ' ' << y + 0.5F * h << ' ';
352  oss << x + 0.5F * w << ' ' << y - 0.5F * h;
353  if (extra.empty() == false) oss << ' ' << extra;
354  break;
355 
356  case jevois::module::SerStyle::Fine:
357  oss << "F2 ";
358  if (id.empty()) oss << "unknown "; else oss << jevois::replaceWhitespace(id) << ' ';
359  oss << 4 << ' '; // number of vertices
360  oss << x - 0.5F * w << ' ' << y - 0.5F * h << ' ';
361  oss << x + 0.5F * w << ' ' << y - 0.5F * h << ' ';
362  oss << x + 0.5F * w << ' ' << y + 0.5F * h << ' ';
363  oss << x + 0.5F * w << ' ' << y - 0.5F * h;
364  if (extra.empty() == false) oss << ' ' << extra;
365  break;
366  }
367 
368  // Send the message:
369  sendSerial(oss.str());
370 }
371 
372 // ####################################################################################################
373 template <typename T>
374 void jevois::StdModule::sendSerialContour2D(unsigned int camw, unsigned int camh, std::vector<cv::Point_<T> > points,
375  std::string const & id, std::string const & extra)
376 {
377  switch (serstyle::get())
378  {
379  case jevois::module::SerStyle::Terse:
380  {
381  // Compute center of gravity:
382  float cx = 0.0F, cy = 0.0F;
383  for (cv::Point const & p : points) { cx += p.x; cy += p.y; }
384  if (points.size()) { cx /= points.size(); cy /= points.size(); }
385  sendSerialImg2D(camw, camh, cx, cy, 0.0F, 0.0F, id, extra);
386  }
387  break;
388 
389  case jevois::module::SerStyle::Normal:
390  {
391  // Compute upright bounding rectangle:
392  cv::Rect r = cv::boundingRect(points);
393  sendSerialImg2D(camw, camh, r.x + 0.5F * r.width, r.y + 0.5F * r.height, r.width, r.height, id, extra);
394  }
395  break;
396 
397  case jevois::module::SerStyle::Detail:
398  {
399  // Compute minimal rotated rectangle enclosing the points:
400  cv::RotatedRect r = cv::minAreaRect(points);
401 
402  // Build the message:
403  unsigned int const prec = serprec::get(); float const eps = std::pow(10.0F, -float(prec));
404  std::ostringstream oss; oss << std::fixed << std::setprecision(prec);
405  oss << "D2 ";
406  if (id.empty()) oss << "unknown "; else oss << jevois::replaceWhitespace(id) << ' ';
407  cv::Point2f corners[4];
408  r.points(corners);
409 
410  oss << 4; // number of vertices
411 
412  for (int i = 0; i < 4; ++i)
413  {
414  float x = corners[i].x, y = corners[i].y;
415  jevois::coords::imgToStd(x, y, camw, camh, eps);
416  oss << ' ' << x << ' ' << y;
417  }
418  if (extra.empty() == false) oss << ' ' << extra;
419 
420  // Send the message:
421  sendSerial(oss.str());
422  }
423  break;
424 
425  case jevois::module::SerStyle::Fine:
426  {
427  // Build the message:
428  unsigned int const prec = serprec::get(); float const eps = std::pow(10.0F, -float(prec));
429  std::ostringstream oss; oss << std::fixed << std::setprecision(prec);
430  oss << "F2 ";
431  if (id.empty()) oss << "unknown "; else oss << jevois::replaceWhitespace(id) << ' ';
432  oss << points.size(); // number of vertices
433 
434  for (cv::Point const & p : points)
435  {
436  float x = p.x, y = p.y;
437  jevois::coords::imgToStd(x, y, camw, camh, eps);
438  oss << ' ' << x << ' ' << y;
439  }
440  if (extra.empty() == false) oss << ' ' << extra;
441 
442  // Send the message:
443  sendSerial(oss.str());
444  }
445  break;
446  }
447 }
448 
449 // Compile in explicit template instantiations:
450 namespace jevois
451 {
452  template
453  void StdModule::sendSerialContour2D(unsigned int camw, unsigned int camh, std::vector<cv::Point_<int> > points,
454  std::string const & id, std::string const & extra);
455  template
456  void StdModule::sendSerialContour2D(unsigned int camw, unsigned int camh, std::vector<cv::Point_<float> > points,
457  std::string const & id, std::string const & extra);
458  template
459  void StdModule::sendSerialContour2D(unsigned int camw, unsigned int camh, std::vector<cv::Point_<double> > points,
460  std::string const & id, std::string const & extra);
461 }
462 
463 // ####################################################################################################
464 void jevois::StdModule::sendSerialStd3D(float x, float y, float z, float w, float h, float d,
465  float q1, float q2, float q3, float q4,
466  std::string const & id, std::string const & extra)
467 {
468  // Build the message depending on desired style:
469  std::ostringstream oss; oss << std::fixed << std::setprecision(serprec::get());
470 
471  switch (serstyle::get())
472  {
473  case jevois::module::SerStyle::Terse:
474  oss << "T3 " << x << ' ' << y << ' ' << z;
475  break;
476 
477  case jevois::module::SerStyle::Normal:
478  oss << "N3 ";
479  if (id.empty()) oss << "unknown "; else oss << jevois::replaceWhitespace(id) << ' ';
480  oss << x << ' ' << y << ' ' << z << ' ' << w << ' ' << h << ' ' << d;
481  break;
482 
483  case jevois::module::SerStyle::Detail:
484  oss << "D3 ";
485  if (id.empty()) oss << "unknown "; else oss << jevois::replaceWhitespace(id) << ' ';
486  oss << x << ' ' << y << ' ' << z << ' ' << w << ' ' << h << ' ' << d << ' '
487  << q1 << ' ' << q2 << ' ' << q3 << ' ' << q4;
488  if (extra.empty() == false) oss << ' ' << extra;
489  break;
490 
491  case jevois::module::SerStyle::Fine:
492  oss << "F3 ";
493  if (id.empty()) oss << "unknown "; else oss << jevois::replaceWhitespace(id) << ' ';
494  oss << 8 << ' '; // number of vertices
495  oss << x - 0.5F * w << ' ' << y - 0.5F * h << ' ' << z - 0.5F * d << ' ';
496  oss << x + 0.5F * w << ' ' << y - 0.5F * h << ' ' << z - 0.5F * d << ' ';
497  oss << x + 0.5F * w << ' ' << y + 0.5F * h << ' ' << z - 0.5F * d << ' ';
498  oss << x + 0.5F * w << ' ' << y - 0.5F * h << ' ' << z - 0.5F * d << ' ';
499  oss << x - 0.5F * w << ' ' << y - 0.5F * h << ' ' << z + 0.5F * d << ' ';
500  oss << x + 0.5F * w << ' ' << y - 0.5F * h << ' ' << z + 0.5F * d << ' ';
501  oss << x + 0.5F * w << ' ' << y + 0.5F * h << ' ' << z + 0.5F * d << ' ';
502  oss << x + 0.5F * w << ' ' << y - 0.5F * h << ' ' << z + 0.5F * d << ' ';
503  if (extra.empty() == false) oss << ' ' << extra;
504  break;
505  }
506 
507  // Send the message:
508  sendSerial(oss.str());
509 }
510 
511 // ####################################################################################################
512 void jevois::StdModule::sendSerialStd3D(std::vector<cv::Point3f> points, std::string const & id,
513  std::string const & extra)
514 {
515  switch (serstyle::get())
516  {
517  case jevois::module::SerStyle::Terse:
518  {
519  // Compute center of gravity:
520  cv::Point3f cg(0.0F, 0.0F, 0.0F);
521  for (cv::Point3f const & p : points) cg += p;
522  if (points.size()) { cg.x /= points.size(); cg.y /= points.size(); cg.z /= points.size(); }
523  sendSerialStd3D(cg.x, cg.y, cg.z, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, id, extra);
524  }
525  break;
526 
527  case jevois::module::SerStyle::Normal:
528  {
529  // Compute upright bounding parallelepiped:
530  cv::Point3f cg(0.0F, 0.0F, 0.0F), pmin(1e30F, 1e30F, 1e30F), pmax(-1e30F, -1e30F, -1e30F);
531  for (cv::Point3f const & p : points)
532  {
533  cg += p;
534  if (p.x < pmin.x) pmin.x = p.x;
535  if (p.y < pmin.y) pmin.y = p.y;
536  if (p.z < pmin.z) pmin.z = p.z;
537  if (p.x > pmax.x) pmax.x = p.x;
538  if (p.y > pmax.y) pmax.y = p.y;
539  if (p.z > pmax.z) pmax.z = p.z;
540  }
541  if (points.size()) { cg.x /= points.size(); cg.y /= points.size(); cg.z /= points.size(); }
542  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,
543  id, extra);
544  }
545  break;
546 
547  case jevois::module::SerStyle::Detail:
548  {
549  // Compute upright bounding parallelepiped:
550  cv::Point3f cg(0.0F, 0.0F, 0.0F), pmin(1e30F, 1e30F, 1e30F), pmax(-1e30F, -1e30F, -1e30F);
551  for (cv::Point3f const & p : points)
552  {
553  cg += p;
554  if (p.x < pmin.x) pmin.x = p.x;
555  if (p.y < pmin.y) pmin.y = p.y;
556  if (p.z < pmin.z) pmin.z = p.z;
557  if (p.x > pmax.x) pmax.x = p.x;
558  if (p.y > pmax.y) pmax.y = p.y;
559  if (p.z > pmax.z) pmax.z = p.z;
560  }
561  if (points.size()) { cg.x /= points.size(); cg.y /= points.size(); cg.z /= points.size(); }
562  // FIXME what should we send for the quaternion?
563  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,
564  id, extra);
565  }
566  break;
567 
568  case jevois::module::SerStyle::Fine:
569  {
570  // Build the message:
571  unsigned int const prec = serprec::get();
572  std::ostringstream oss; oss << std::fixed << std::setprecision(prec);
573  oss << "F3 ";
574  if (id.empty()) oss << "unknown "; else oss << jevois::replaceWhitespace(id) << ' ';
575  oss << points.size(); // number of vertices
576 
577  for (cv::Point3f const & p : points) oss << ' ' << p.x << ' ' << p.y << ' ' << p.z;
578  if (extra.empty() == false) oss << ' ' << extra;
579 
580  // Send the message:
581  sendSerial(oss.str());
582  }
583  break;
584  }
585 }
cv::Mat convertToCvRGB(RawImage const &src)
Convert RawImage to OpenCV doing color conversion from any RawImage source pixel to OpenCV RGB byte...
Definition: RawImageOps.C:302
cv::Mat convertToCvRGBA(RawImage const &src)
Convert RawImage to OpenCV doing color conversion from any RawImage source pixel to OpenCV RGB-A byte...
Definition: RawImageOps.C:325
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:374
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
Exception-safe wrapper around a raw camera input frame.
Definition: Module.H:56
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
cv::Mat convertToCvBGR(RawImage const &src)
Convert RawImage to OpenCV doing color conversion from any RawImage source pixel to OpenCV BGR byte...
Definition: RawImageOps.C:279
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:240
void send(RawImage const &img) override
Send an image out over USB to the host computer.
Definition: Gadget.C:839
cv::Mat getCvRGBA(bool casync=false) const
Shorthand to get the input image as a RGBA cv::Mat and release the raw buffer.
Definition: Module.C:94
void sendCvRGBA(cv::Mat const &img, int quality=75) const
Shorthand to send a RGBA cv::Mat after converting it to the current output format.
Definition: Module.C:172
void send() const
Send an image out over USB to the host computer.
Definition: Module.C:141
Module(std::string const &instance)
Constructor.
Definition: Module.C:181
void sendCvRGB(cv::Mat const &img, int quality=75) const
Shorthand to send a RGB cv::Mat after converting it to the current output format. ...
Definition: Module.C:164
RawImage const & get(bool casync=false) const
Get the next captured camera image.
Definition: Module.C:51
void sendCvGRAY(cv::Mat const &img, int quality=75) const
Shorthand to send a GRAY cv::Mat after converting it to the current output format.
Definition: Module.C:149
InputFrame(InputFrame &&other)=default
Move constructor.
virtual void supportedCommands(std::ostream &os)
Human-readable description of this Module&#39;s supported custom commands.
Definition: Module.C:212
void sendSerial(std::string const &str, bool islog=false)
Send a string to all serial ports.
Definition: Engine.C:825
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:143
void sendCvBGR(cv::Mat const &img, int quality=75) const
Shorthand to send a BGR cv::Mat after converting it to the current output format. ...
Definition: Module.C:157
A component of a model hierarchy.
Definition: Component.H:176
virtual void process(InputFrame &&inframe, OutputFrame &&outframe)
Processing function, version that receives a frame from camera and sends a frame out over USB...
StdModule(std::string const &instance)
Constructor.
Definition: Module.C:217
A raw image as coming from a V4L2 Camera and/or being sent out to a USB Gadget.
Definition: RawImage.H:110
cv::Mat getCvRGB(bool casync=false) const
Shorthand to get the input image as a RGB cv::Mat and release the raw buffer.
Definition: Module.C:85
virtual void done(RawImage &img)=0
Indicate that user processing is done with an image previously obtained via get() ...
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:328
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:315
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
virtual void get(RawImage &img)=0
Get the next captured buffer.
cv::Mat convertToCvGray(RawImage const &src)
Convert RawImage to OpenCV doing color conversion from any RawImage source pixel to OpenCV gray byte...
Definition: RawImageOps.C:245
void convertCvBGRtoRawImage(cv::Mat const &src, RawImage &dst, int quality)
Convert a BGR cv::Mat to RawImage with already-allocated pixels and pixel type.
Definition: RawImageOps.C:1180
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
virtual void sendSerial(std::string const &str)
Send a string over the &#39;serout&#39; serial port.
Definition: Module.C:198
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:271
cv::Mat getCvGRAY(bool casync=false) const
Shorthand to get the input image as a GRAY cv::Mat and release the raw buffer.
Definition: Module.C:67
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:464
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:226
#define LFATAL(msg)
Convenience macro for users to print out console or syslog messages, FATAL level. ...
Definition: Log.H:212
virtual ~StdModule()
Virtual destructor for safe inheritance.
Definition: Module.C:222
void convertCvRGBAtoRawImage(cv::Mat const &src, RawImage &dst, int quality)
Convert an RGBA cv::Mat to RawImage with already-allocated pixels and pixel type. ...
Definition: RawImageOps.C:1246
JeVois processing engine - gets images from camera sensor, processes them, and sends results over USB...
Definition: Engine.H:229
void convertCvGRAYtoRawImage(cv::Mat const &src, RawImage &dst, int quality)
Convert a Gray cv::Mat to RawImage with already-allocated pixels and pixel type.
Definition: RawImageOps.C:1266
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:207
Virtual base class for a vision processing module.
Definition: Module.H:279
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:284
Exception-safe wrapper around a raw image to be sent over USB.
Definition: Module.H:144
~InputFrame()
Destructor, returns the buffers to the driver as needed.
Definition: Module.C:38
RawImage const & get() const
Get a pre-allocated image so that we can fill the pixel data and later send out over USB using send()...
Definition: Module.C:133
cv::Mat getCvBGR(bool casync=false) const
Shorthand to get the input image as a BGR cv::Mat and release the raw buffer.
Definition: Module.C:76
void done() const
Indicate that user processing is done with the image previously obtained via get() ...
Definition: Module.C:60
~OutputFrame()
Destructor, returns the buffers to the driver as needed.
Definition: Module.C:109
virtual ~Module()
Virtual destructor for safe inheritance.
Definition: Module.C:186
void convertCvRGBtoRawImage(cv::Mat const &src, RawImage &dst, int quality)
Convert a RGB cv::Mat to RawImage with already-allocated pixels and pixel type.
Definition: RawImageOps.C:1201