YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
FakeFrameGrabber.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include "FakeFrameGrabber.h"
8
10#include <yarp/os/LogStream.h>
11#include <yarp/sig/ImageDraw.h>
12
13#include <cstdio>
14#include <thread>
15#include <random>
16
17using namespace yarp::os;
18using namespace yarp::dev;
19using namespace yarp::sig;
20using namespace yarp::sig::draw;
21
22namespace {
23YARP_LOG_COMPONENT(FAKEFRAMEGRABBER, "yarp.device.fakeFrameGrabber")
24
25//the following data are used by [time] test
26constexpr char num[12][16]
27{
28 // '0'
29 "***"
30 "* *"
31 "* *"
32 "* *"
33 "***",
34
35 // '1'
36 " * "
37 " * "
38 " * "
39 " * "
40 " * ",
41
42 // '2'
43 "***"
44 " *"
45 "***"
46 "* "
47 "***",
48
49 // '3'
50 "***"
51 " *"
52 "***"
53 " *"
54 "***",
55
56 // '4'
57 "* *"
58 "* *"
59 "***"
60 " *"
61 " *",
62
63 // '5'
64 "***"
65 "* "
66 "***"
67 " *"
68 "***",
69
70 // '6'
71 "***"
72 "* "
73 "***"
74 "* *"
75 "***",
76
77 // '7'
78 "***"
79 " *"
80 " *"
81 " *"
82 " *",
83
84 // '8'
85 "***"
86 "* *"
87 "***"
88 "* *"
89 "***",
90
91 // '9'
92 "***"
93 "* *"
94 "***"
95 " *"
96 "***",
97
98 // ' '
99 " "
100 " "
101 " "
102 " "
103 " ",
104
105 // '.'
106 " "
107 " "
108 " "
109 " **"
110 " **",
111};
112constexpr size_t num_width = 3;
113constexpr size_t num_height = 5;
114
115} // namespace
116
118{
119 yarp::os::Bottle command;
120 yarp::os::Bottle reply;
121 bool ok = command.read(connection);
122 if (!ok) {
123 return false;
124 }
125 reply.clear();
126
127 if (command.get(0).asString()=="help")
128 {
129 reply.addVocab32("many");
130 reply.addString("set_mode <mode>");
131 reply.addString("set_image <file_name>/off");
132 reply.addString("available modes: ball, line, grid, size, rand, none, time");
133 reply.addString("set_noise on/off");
134 reply.addString("set_snr <snr>");
135 reply.addString("");
136 }
137 else if (command.get(0).asString() == "set_mode")
138 {
139 m_mode= command.get(1).asString();
140 reply.addString("ack");
141 }
142 else if (command.get(0).asString() == "set_image")
143 {
144 if (command.get(1).asString() == "off")
145 {
146 have_bg=false;
147 reply.addString("ack");
148 }
149 else
150 {
151 if (yarp::sig::file::read(background, command.get(1).asString()))
152 {
153 m_width = background.width();
154 m_height = background.height();
155 have_bg = true;
156 reply.addString("ack");
157 }
158 else
159 {
160 have_bg = false;
161 reply.addString("err");
162 }
163 }
164 }
165 else if (command.get(0).asString() == "set_noise")
166 {
167 if (command.get(1).asString() == "off") {
168 m_add_noise = false;
169 reply.addString("ack");
170 } else if (command.get(1).asString() == "on") {
171 m_add_noise = true;
172 reply.addString("ack");
173 } else {
174 reply.addString("err");
175 }
176 }
177 else if (command.get(0).asString() == "set_snr")
178 {
179 m_snr = yarp::conf::clamp(command.get(1).asFloat64(), 0.0, 1.0);
180 reply.addString("ack");
181 }
182 else
183 {
184 reply.addString("Unknown command. Type 'help'.");
185 }
186
188 if (returnToSender != nullptr)
189 {
190 reply.write(*returnToSender);
191 }
192
193 return true;
194}
195
197 stop();
198 m_rpcPort.close();
199 return true;
200}
201
203{
204 if (!this->parseParams(config)) {return false;}
205
206 m_intrinsic.put("physFocalLength",m_physFocalLength);
207 m_intrinsic.put("focalLengthX",m_focalLengthX);
208 m_intrinsic.put("focalLengthY",m_focalLengthY);
209 m_intrinsic.put("principalPointX",m_principalPointX);
210 m_intrinsic.put("principalPointY",m_principalPointY);
211
212 Value* val = Value::makeList();
213 auto* bb = val->asList();
214 for (double num : m_rectificationMatrix) { bb->addFloat64(num); }
215 m_intrinsic.put("rectificationMatrix",val);
216
217 m_intrinsic.put("distortionModel", m_distortionModel);
218 m_intrinsic.put("k1",m_k1);
219 m_intrinsic.put("k2",m_k2);
220 m_intrinsic.put("k3",m_k3);
221 m_intrinsic.put("t1",m_t1);
222 m_intrinsic.put("t2",m_t2);
223 //Only for debug
225 conf1.height=128;
226 conf1.width=128;
227 conf1.framerate=60.0;
228 conf1.pixelCoding=VOCAB_PIXEL_RGB;
229 configurations.push_back(conf1);
230
232 conf2.height=256;
233 conf2.width=256;
234 conf2.framerate=30.0;
235 conf2.pixelCoding=VOCAB_PIXEL_BGR;
236 configurations.push_back(conf2);
237
239 conf3.height=512;
240 conf3.width=512;
241 conf3.framerate=15.0;
242 conf3.pixelCoding=VOCAB_PIXEL_MONO;
243 configurations.push_back(conf3);
244
245 if (m_freq>0)
246 {
247 m_period = 1/ m_freq;
248 }
249 else if (m_period>0)
250 {
251 //ok
252 }
253 else
254 {
255 yCWarning(FAKEFRAMEGRABBER, "Either `period` or `freq` parameters must be a valid >0 value");
256 }
257
258 if (!m_src.empty())
259 {
260 if (!yarp::sig::file::read(background, m_src))
261 {
262 yCWarning(FAKEFRAMEGRABBER, "Unable to open file");
263 return false;
264 }
265 }
266 if (background.width()>0)
267 {
268 if (m_width>0 || m_height>0)
269 {
270 yCWarning(FAKEFRAMEGRABBER, "width and height options are ignored when passing a background image");
271 }
272 m_width = background.width();
273 m_height = background.height();
274 have_bg = true;
275 }
276
277
278 m_snr = yarp::conf::clamp(m_snr, 0.0, 1.0);
279 m_mono = m_mono || m_bayer;
280
282 "Test grabber period %g / freq %g , mode %s",
283 m_period,
284 (1.0/m_period),
285 m_mode.c_str());
286
287 bx = m_width/2;
288 by = m_height/2;
289
290 for (auto& buff : buffs) {
291 buff.resize(m_width, m_height);
292 buff.zero();
293 }
294
295 if (!m_rpcPort.open(m_fakeFrameGrabber_rpc_port.c_str()))
296 {
297 yCError(FAKEFRAMEGRABBER, "Failed to open port %s", m_fakeFrameGrabber_rpc_port.c_str());
298 yCError(FAKEFRAMEGRABBER, "Do you have multiple FakeFrameGrabber devices running?");
299 yCError(FAKEFRAMEGRABBER, "If yes, use the `fakeFrameGrabber_rpc_port` parameter to set a different name for each of them");
300 return false;
301 }
302 m_rpcPort.setReader(*this);
303
304 start();
305
306 return true;
307}
308
310 double now = yarp::os::Time::now();
311
312 if (now-prev>1000) {
313 first = now;
314 prev = now;
315 }
316 double dt = m_period-(now-prev);
317
318 if (dt>0) {
320 }
321
322 // this is the controlled instant when we consider the
323 // image as going out
324 prev += m_period;
325}
326
328 return m_height;
329}
330
332 return m_width;
333}
334
338
342
344 configurations=this->configurations;
345 return true;
346}
347
348bool FakeFrameGrabber::getRgbResolution(int &width, int &height){
351 return true;
352}
353
354bool FakeFrameGrabber::setRgbResolution(int width, int height){
355 m_width =width;
357 return true;
358}
359
360bool FakeFrameGrabber::getRgbFOV(double &horizontalFov, double &verticalFov){
361 horizontalFov=this->m_horizontalFov;
362 verticalFov=this->m_verticalFov;
363 return true;
364}
365
366bool FakeFrameGrabber::setRgbFOV(double horizontalFov, double verticalFov){
367 this->m_horizontalFov=horizontalFov;
368 this->m_verticalFov=verticalFov;
369 return true;
370}
371
373 intrinsic=this->m_intrinsic;
374 return true;
375}
376
378 mirror=this->m_mirror;
379 return true;}
380
382 this->m_mirror =mirror;
383 return true;
384}
385
387{
388 while (!isStopping()) {
389 for (size_t i = 0; i < 2 && !isStopping(); ++i) {
390 if (!m_syncro) {
391 std::unique_lock<std::mutex> lk(mutex[i]);
392 createTestImage(buffs[i], buff_ts[i]);
393 timing();
394 lk.unlock();
395
396 curr_buff_mutex.lock();
397 curr_buff = i;
398 curr_buff_mutex.unlock();
399 std::this_thread::yield();
400 } else {
401 std::unique_lock<std::mutex> lk(mutex[i]);
402 img_consumed_cv[i].wait(lk, [&]{ if (img_ready[i]) {img_ready_cv[i].notify_one();} return (isStopping() || img_consumed[i]);});
403 if (isStopping()) {
404 break;
405 }
406 img_ready[i] = false;
407 img_consumed[i] = false;
408 createTestImage(buffs[i], buff_ts[i]);
409 img_ready[i] = true;
410 img_ready_cv[i].notify_all();
411 }
412 }
413 }
414}
415
417{
418 // Unlock any blocked thread.
419 if (m_syncro) {
420 for (size_t i = 0; i < 2; ++i) {
421 std::unique_lock<std::mutex> lk(mutex[i]);
422 img_consumed[i] = true;
423 img_consumed_cv[i].notify_all();
424 img_ready[i] = true;
425 img_ready_cv[i].notify_all();
426 }
427 }
428}
429
430
432{
433 if (!isRunning()) {
434 return false;
435 }
436
437 if (!m_syncro) {
438 curr_buff_mutex.lock();
439 size_t cb = curr_buff;
440 std::unique_lock<std::mutex> lk(mutex[cb]);
441 // Release the mutex after we get the lock on current image to avoid
442 // that the image is swapped while we are waiting to read it
443 curr_buff_mutex.unlock();
444 image.copy(buffs[cb]);
445 stamp.update(buff_ts[cb]);
446 } else {
447 curr_buff_mutex.lock();
448 timing();
449 size_t cb = curr_buff;
450 std::unique_lock<std::mutex> lk(mutex[cb]);
451 img_ready_cv[cb].wait(lk, [&]{return (!isRunning() || img_ready[cb]);});
452 if (!isRunning()) {
453 return false;
454 }
455
456 image.copy(buffs[cb]);
457 stamp.update(buff_ts[cb]);
458 img_consumed[cb] = true;
459 img_consumed_cv[cb].notify_one();
460
461 curr_buff = (cb + 1) % 2;
462 curr_buff_mutex.unlock();
463 }
464
465 return true;
466}
467
469{
470 if (!isRunning()) {
471 return false;
472 }
473
474 if (!m_syncro) {
475 curr_buff_mutex.lock();
476 size_t cb = curr_buff;
477 std::unique_lock<std::mutex> lk(mutex[cb]);
478 curr_buff_mutex.unlock();
479 if (m_bayer) {
480 makeSimpleBayer(buffs[cb], image);
481 } else {
482 image.copy(buffs[cb]);
483 }
484 stamp.update(buff_ts[cb]);
485 } else {
486 curr_buff_mutex.lock();
487 timing();
488 size_t cb = curr_buff;
489 std::unique_lock<std::mutex> lk(mutex[cb]);
490 img_ready_cv[cb].wait(lk, [&]{return (!isRunning() || img_ready[cb]);});
491 if (!isRunning()) {
492 return false;
493 }
494 if (m_bayer) {
495 makeSimpleBayer(buffs[cb], image);
496 } else {
497 image.copy(buffs[cb]);
498 }
499 stamp.update(buff_ts[cb]);
500 img_consumed[cb] = true;
501 img_consumed_cv[cb].notify_one();
502
503 curr_buff = (cb + 1) % 2;
504 curr_buff_mutex.unlock();
505 }
506
507 return true;
508}
509
511 yarp::sig::VectorOf<std::pair<int, int>> vertices,
513{
514 yCDebugThrottle(FAKEFRAMEGRABBER, 5.0) << "Hardware crop requested!";
516}
517
519 yarp::sig::VectorOf<std::pair<int, int>> vertices,
521{
522 yCDebugThrottle(FAKEFRAMEGRABBER, 5.0) << "Hardware crop requested!";
524}
525
529
530bool FakeFrameGrabber::hasAudio() { return false; }
531
533
535 return m_mono;
536}
537
539bool FakeFrameGrabber::hasFeature(int feature, bool *hasFeature) { return false; }
540bool FakeFrameGrabber::setFeature(int feature, double value) { return false; }
541bool FakeFrameGrabber::getFeature(int feature, double *value) { return false; }
542bool FakeFrameGrabber::setFeature(int feature, double value1, double value2) { return false; }
543bool FakeFrameGrabber::getFeature(int feature, double *value1, double *value2) { return false; }
544bool FakeFrameGrabber::hasOnOff(int feature, bool *HasOnOff) { return false; }
545bool FakeFrameGrabber::setActive(int feature, bool onoff) { return false; }
546bool FakeFrameGrabber::getActive(int feature, bool *isActive) { return false; }
547bool FakeFrameGrabber::hasAuto(int feature, bool *hasAuto) { return false; }
548bool FakeFrameGrabber::hasManual(int feature, bool *hasManual) { return false; }
549bool FakeFrameGrabber::hasOnePush(int feature, bool *hasOnePush) { return false; }
550bool FakeFrameGrabber::setMode(int feature, FeatureMode mode) { return false; }
551bool FakeFrameGrabber::getMode(int feature, FeatureMode *mode) { return false; }
552bool FakeFrameGrabber::setOnePush(int feature) { return false; }
553
554void FakeFrameGrabber::printTime(unsigned char* pixbuf, size_t pixbuf_w, size_t pixbuf_h, size_t x, size_t y, char* s, size_t size)
555{
556 for (size_t i = 0; i < size; i++)
557 {
558 const char* num_p = nullptr;
559 switch (s[i]) {
560 case '0': num_p = num[0]; break;
561 case '1': num_p = num[1]; break;
562 case '2': num_p = num[2]; break;
563 case '3': num_p = num[3]; break;
564 case '4': num_p = num[4]; break;
565 case '5': num_p = num[5]; break;
566 case '6': num_p = num[6]; break;
567 case '7': num_p = num[7]; break;
568 case '8': num_p = num[8]; break;
569 case '9': num_p = num[9]; break;
570 case ' ': num_p = num[10]; break;
571 case '.': num_p = num[11]; break;
572 default: num_p = num[10]; break;
573 }
574
575 for (size_t yi = 0; yi < num_height; yi++) {
576 for (size_t xi = 0; xi < num_width; xi++) {
577 size_t ii = yi * num_width + xi;
578 if (num_p[ii] == '*') {
579 for (size_t r = yi * num_height; r < yi*num_height + num_height; r++) {
580 size_t off = i * (num_height + 20);
581 for (size_t c = xi * num_height + off; c < xi*num_height + num_height + off; c++) {
582 if (c >= pixbuf_h || r >= pixbuf_w) {
583 //avoid drawing out of the image memory
584 return;
585 }
586 unsigned char *pixel = pixbuf;
587 size_t offset = c * sizeof(yarp::sig::PixelRgb) + r * (pixbuf_w * sizeof(yarp::sig::PixelRgb));
588 pixel = pixel + offset;
589 pixel[0] = 0;
590 pixel[1] = 0;
591 pixel[2] = 255;
592 }
593 }
594 }
595 }
596 }
597 }
598}
599
600void FakeFrameGrabber::createTestImage(yarp::sig::ImageOf<yarp::sig::PixelRgb>& image,
601 double& timestamp) {
602 // to test IPreciselyTimed, make timestamps be mysteriously NNN.NNN42
603 double t = Time::now();
604 t -= (((t*1000) - static_cast<int64_t>(t*1000)) / 1000);
605 t += 0.00042;
606 timestamp = t;
607 image.resize(m_width,m_height);
608
609 if (m_mode == "[Time]")
610 {
611 {
612 if (have_bg) {
613 image.copy(background);
614 } else {
615 image.zero();
616 }
617 char txtbuf[50];
618 static const double start_time = t;
619 double time = t - start_time;
620 std::snprintf(txtbuf, 50, "%.3f", time);
621 int len = strlen(txtbuf);
622 if (len < 20)
623 {
624 printTime((unsigned char*)image.getRawImage(), image.width(), image.height(), 0, 0, txtbuf, len);
625 }
626 }
627 }
628 else if (m_mode == "[ball]")
629 {
630 {
631 if (have_bg) {
632 image.copy(background);
633 } else {
634 image.zero();
635 }
636 addCircle(image,PixelRgb{0,255,0},bx,by,15);
637 addCircle(image,PixelRgb{0,255,255},bx,by,8);
638 if (ct%5!=0) {
639 rnd *= 65537;
640 rnd += 17;
641 int delta_x = (rnd % 5) - 2;
642 bx += delta_x;
643 rnd *= 65537;
644 rnd += 17;
645 int delta_y = (rnd % 5) - 2;
646 by += delta_y;
647 } else {
648 int dx = m_width/2 - bx;
649 int dy = m_height/2 - by;
650 if (dx>0) { bx++; }
651 if (dx<0) { bx--; }
652 if (dy>0) { by++; }
653 if (dy<0) { by--; }
654 }
655 }
656 }
657 else if (m_mode == "[grid]")
658 {
659 {
660 size_t ww = image.width();
661 size_t hh = image.height();
662 if (ww>1&&hh>1) {
663 for (size_t x=0; x<ww; x++) {
664 for (size_t y=0; y<hh; y++) {
665 double xx = ((double)x)/(ww-1);
666 double yy = ((double)y)/(hh-1);
667 bool act = (y==ct);
668 auto r = static_cast<unsigned char>(0.5 + 255 * xx);
669 auto g = static_cast<unsigned char>(0.5 + 255 * yy);
670 auto b = static_cast<unsigned char>(act * 255);
671 image.pixel(x, y) = PixelRgb{r, g, b};
672 }
673 }
674 }
675 }
676 }
677 else if (m_mode == "[size]")
678 {
679 static int count = 0;
680 count++;
681 if (count== 100)
682 {
683 yCDebug(FAKEFRAMEGRABBER) << "size 100, 100";
684 image.resize(100,100);
685 }
686 else if (count == 200)
687 {
688 yCDebug(FAKEFRAMEGRABBER) << "size 200, 100";
689 image.resize(200, 100);
690 }
691 else if (count == 300)
692 {
693 yCDebug(FAKEFRAMEGRABBER) << "size 300, 50";
694 image.resize(300, 50);
695 count = 0;
696 }
697
698 size_t ww = m_width = image.width();
699 size_t hh = m_height = image.height();
700 if (ww>1 && hh>1) {
701 for (size_t x = 0; x<ww; x++) {
702 for (size_t y = 0; y<hh; y++) {
703 double xx = ((double)x) / (ww - 1);
704 double yy = ((double)y) / (hh - 1);
705 bool act = (y == ct);
706 auto r = static_cast<unsigned char>(0.5 + 255 * xx);
707 auto g = static_cast<unsigned char>(0.5 + 255 * yy);
708 auto b = static_cast<unsigned char>(act * 255);
709 image.pixel(x, y) = PixelRgb{r, g, b};
710 }
711 }
712 }
713 }
714 else if (m_mode == "[line]")
715 {
716 {
717 if (have_bg) {
718 image.copy(background);
719 } else {
720 image.zero();
721 }
722 for (size_t i=0; i<image.width(); i++) {
723 image.pixel(i,ct).r = 255;
724 }
725 }
726 }
727 else if (m_mode == "[rand]")
728 {
729 {
730 static unsigned char r = 128;
731 static unsigned char g = 128;
732 static unsigned char b = 128;
733
734 size_t ww = image.width();
735 size_t hh = image.height();
736
737 if (ww>1&&hh>1) {
738 for (size_t x=0; x<ww; x++) {
739 for (size_t y=0; y<hh; y++) {
740 r += udist(randengine);
741 g += udist(randengine);
742 b += udist(randengine);
743 image.pixel(x,y) = PixelRgb{r,g,b};
744 }
745 }
746 }
747 }
748 }
749 else if (m_mode == "[none]")
750 {
751 {
752 if (have_bg) {
753 image.copy(background);
754 } else {
755 image.zero();
756 }
757 }
758 }
759 else
760 {
761 yCError(FAKEFRAMEGRABBER, "Invalid mode %s", m_mode.c_str());
762 }
763
764 ct++;
765 if (ct>=image.height()) {
766 ct = 0;
767 }
768 if (by>=image.height()) {
769 by = image.height()-1;
770 }
771 if (bx>=image.width()) {
772 bx = image.width()-1;
773 }
774
775 if (m_add_noise) {
776 static const double nsr = 1.0 - m_snr;
777 for (size_t x = 0; x < image.width(); ++x) {
778 for (size_t y = 0; y < image.height(); ++y) {
779 auto rand = ucdist(randengine);
780 image.pixel(x,y) = PixelRgb {
781 static_cast<unsigned char>(image.pixel(x,y).r * m_snr + (rand * nsr * 255)),
782 static_cast<unsigned char>(image.pixel(x,y).g * m_snr + (rand * nsr * 255)),
783 static_cast<unsigned char>(image.pixel(x,y).b * m_snr + (rand * nsr * 255))
784 };
785 }
786 }
787 }
788
789 if (m_add_timestamp) {
790 char ttxt[50];
791 std::snprintf(ttxt, 50, "%021.10f", timestamp);
792 image.pixel(0, 0).r = ttxt[0] - '0';
793 image.pixel(0, 0).g = ttxt[1] - '0';
794 image.pixel(0, 0).b = ttxt[2] - '0';
795
796 image.pixel(1, 0).r = ttxt[3] - '0';
797 image.pixel(1, 0).g = ttxt[4] - '0';
798 image.pixel(1, 0).b = ttxt[5] - '0';
799
800 image.pixel(2, 0).r = ttxt[6] - '0';
801 image.pixel(2, 0).g = ttxt[7] - '0';
802 image.pixel(2, 0).b = ttxt[8] - '0';
803
804 image.pixel(3, 0).r = ttxt[9] - '0';
805 image.pixel(3, 0).g = ttxt[10] - '0';
806 image.pixel(3, 0).b = ttxt[11] - '0';
807
808 image.pixel(4, 0).r = ttxt[12] - '0';
809 image.pixel(4, 0).g = ttxt[13] - '0';
810 image.pixel(4, 0).b = ttxt[14] - '0';
811
812 image.pixel(5, 0).r = ttxt[15] - '0';
813 image.pixel(5, 0).g = ttxt[16] - '0';
814 image.pixel(5, 0).b = ttxt[17] - '0';
815
816 image.pixel(6, 0).r = ttxt[18] - '0';
817 image.pixel(6, 0).g = ttxt[19] - '0';
818 image.pixel(6, 0).b = ttxt[20] - '0';
819 }
820}
821
822
823
824// From iCub staticgrabber device.
825// DF2 bayer sequence.
826// -- in staticgrabber: first row GBGBGB, second row RGRGRG.
827// -- changed here to: first row GRGRGR, second row BGBGBG.
828bool FakeFrameGrabber::makeSimpleBayer(
831
832 bayer.resize(img.width(), img.height());
833
834 const size_t w = img.width();
835 const size_t h = img.height();
836
837 size_t i, j;
838 for (i = 0; i < h; i++) {
839 auto* row = (PixelRgb *)img.getRow(i);
840 auto* rd = (PixelMono *)bayer.getRow(i);
841
842 for (j = 0; j < w; j++) {
843
844 if ((i%2) == 0) {
845 switch (j%4) {
846 case 0:
847 case 2:
848 *rd++ = row->g;
849 row++;
850 break;
851
852 case 1:
853 case 3:
854 *rd++ = row->r;
855 row++;
856 break;
857 }
858 }
859
860 if ((i%2) == 1) {
861 switch (j%4) {
862 case 1:
863 case 3:
864 *rd++ = row->g;
865 row++;
866 break;
867
868 case 0:
869 case 2:
870 *rd++ = row->b;
871 row++;
872 break;
873 }
874 }
875 }
876 }
877
878 return true;
879}
float t
cropType_id_t
@ VOCAB_PIXEL_BGR
Definition Image.h:49
@ VOCAB_PIXEL_MONO
Definition Image.h:42
@ VOCAB_PIXEL_RGB
Definition Image.h:44
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
int width() const override
Return the width of each frame.
bool getCameraDescription(CameraDescriptor *camera) override
Get a basic description of the camera hw.
bool hasFeature(int feature, bool *hasFeature) override
Check if camera has the requested feature (saturation, brightness ... )
bool getMode(int feature, FeatureMode *mode) override
Get the current mode for the feature.
bool setFeature(int feature, double value) override
Set the requested feature to a value (saturation, brightness ... )
int getRgbWidth() override
Return the width of each frame.
int getRgbHeight() override
Return the height of each frame.
yarp::os::Stamp getLastInputStamp() override
Return the time stamp relative to the last acquisition.
bool setOnePush(int feature) override
Set the requested feature to a value (saturation, brightness ... )
bool getRgbResolution(int &width, int &height) override
Get the resolution of the rgb image from the camera.
bool getRgbIntrinsicParam(yarp::os::Property &intrinsic) override
Get the intrinsic parameters of the rgb camera.
bool getActive(int feature, bool *isActive) override
Get the current status of the feature, on or off.
bool hasVideo() override
bool getRgbSupportedConfigurations(yarp::sig::VectorOf< yarp::dev::CameraConfig > &configurations) override
Get the possible configurations of the camera.
bool hasOnePush(int feature, bool *hasOnePush) override
Check if the requested feature has the 'onePush' mode.
int height() const override
Return the height of each frame.
bool setMode(int feature, FeatureMode mode) override
Set the requested mode for the feature.
bool hasManual(int feature, bool *hasManual) override
Check if the requested feature has the 'manual' mode.
bool getRgbMirroring(bool &mirror) override
Get the mirroring setting of the sensor.
bool hasAuto(int feature, bool *hasAuto) override
Check if the requested feature has the 'auto' mode.
bool hasOnOff(int feature, bool *HasOnOff) override
Check if the camera has the ability to turn on/off the requested feature.
bool getFeature(int feature, double *value) override
Get the current value for the requested feature.
bool getRgbFOV(double &horizontalFov, double &verticalFov) override
Get the field of view (FOV) of the rgb camera.
bool setRgbMirroring(bool mirror) override
Set the mirroring setting of the sensor.
bool setActive(int feature, bool onoff) override
Set the requested feature on or off.
bool open(yarp::os::Searchable &config) override
bool setRgbResolution(int width, int height) override
Set the resolution of the rgb image from the camera.
bool setRgbFOV(double horizontalFov, double verticalFov) override
Set the field of view (FOV) of the rgb camera.
void run() override
Main body of the new thread.
void onStop() override
Call-back, called while halting the thread (before join).
bool getImage(yarp::sig::ImageOf< yarp::sig::PixelRgb > &image) override
Get an image from the frame grabber.
bool getImageCrop(cropType_id_t cropType, yarp::sig::VectorOf< std::pair< int, int > > vertices, yarp::sig::ImageOf< yarp::sig::PixelRgb > &image) override
Get a crop of the image from the frame grabber.
bool hasAudio() override
bool hasRawVideo() override
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
bool close() override
Close the DeviceDriver.
Read a YARP-format image (of a specific type) from a device.
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
void addVocab32(yarp::conf::vocab32_t x)
Places a vocabulary item in the bottle, at the end of the list.
Definition Bottle.cpp:164
bool read(ConnectionReader &reader) override
Set the bottle's value based on input from a network connection.
Definition Bottle.cpp:240
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition Bottle.cpp:246
void clear()
Empties the bottle of any objects it contains.
Definition Bottle.cpp:121
bool write(ConnectionWriter &writer) const override
Output a representation of the bottle to a network connection.
Definition Bottle.cpp:230
void addString(const char *str)
Places a string in the bottle, at the end of the list.
Definition Bottle.cpp:170
A mini-server for performing network communication in the background.
An interface for reading from a network connection.
An interface for writing to a network connection.
void setReader(PortReader &reader) override
Set an external reader for port data.
Definition Port.cpp:511
void close() override
Stop port activity.
Definition Port.cpp:363
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
Definition Port.cpp:79
A class for storing options and configuration information.
Definition Property.h:33
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
Definition Property.cpp:987
A base class for nested structures that can be searched.
Definition Searchable.h:31
An abstraction for a time stamp and/or sequence number.
Definition Stamp.h:21
void update()
Set the timestamp to the current time, and increment the sequence number (wrapping to 0 if the sequen...
Definition Stamp.cpp:124
bool stop()
Stop the thread.
Definition Thread.cpp:81
bool isStopping()
Returns true if the thread is stopping (Thread::stop has been called).
Definition Thread.cpp:99
bool isRunning()
Returns true if the thread is running (Thread::start has been called successfully and the thread has ...
Definition Thread.cpp:105
bool start()
Start the new thread running.
Definition Thread.cpp:93
A single value (typically within a Bottle).
Definition Value.h:43
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
Definition Value.cpp:222
static Value * makeList()
Create a list Value.
Definition Value.cpp:440
virtual Bottle * asList() const
Get list value.
Definition Value.cpp:240
virtual std::string asString() const
Get string value.
Definition Value.cpp:234
Typed image class.
Definition Image.h:605
T & pixel(size_t x, size_t y)
Definition Image.h:621
size_t width() const
Gets width of image in pixels.
Definition Image.h:171
unsigned char * getRawImage() const
Access to the internal image buffer.
Definition Image.cpp:479
bool copy(const Image &alt)
Copy operator.
Definition Image.cpp:624
void resize(size_t imgWidth, size_t imgHeight)
Reallocate an image to be of a desired size, throwing away its current contents.
Definition Image.cpp:402
void zero()
Set all pixels to 0.
Definition Image.cpp:395
size_t height() const
Gets height of image in pixels.
Definition Image.h:177
void push_back(const T &elem)
Push a new element in the vector: size is changed.
Definition Vector.h:249
#define yCInfo(component,...)
#define yCError(component,...)
#define yCDebugThrottle(component, period,...)
#define yCWarning(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
constexpr const T & clamp(const T &v, const T &lo, const T &hi)
Definition numeric.h:91
For streams capable of holding different kinds of content, check what they actually have.
Definition jointData.cpp:13
double now()
Return the current time in seconds, relative to an arbitrary starting point.
Definition Time.cpp:121
void delay(double seconds)
Wait for a certain number of seconds.
Definition Time.cpp:111
An interface to the operating system, including Port based communication.
void addCircle(ImageOf< T > &dest, const T &pix, int i, int j, int r)
Definition ImageDraw.h:32
bool read(ImageOf< PixelRgb > &dest, const std::string &src, image_fileformat format=FORMAT_ANY)
Struct describing a possible camera configuration.