|
YARP
Yet Another Robot Platform
|
|
Go to the documentation of this file.
53 std::snprintf(num[0].data, 16,
"**** ** ** ****");
54 std::snprintf(num[1].data, 16,
" * * * * * ");
55 std::snprintf(num[2].data, 16,
"*** ***** ***");
56 std::snprintf(num[3].data, 16,
"*** **** ****");
57 std::snprintf(num[4].data, 16,
"* ** **** * *");
58 std::snprintf(num[5].data, 16,
"**** *** ****");
59 std::snprintf(num[6].data, 16,
"**** **** ****");
60 std::snprintf(num[7].data, 16,
"*** * * * *");
61 std::snprintf(num[8].data, 16,
"**** ***** ****");
62 std::snprintf(num[9].data, 16,
"**** **** ****");
63 std::snprintf(num[10].data, 16,
" ");
64 std::snprintf(num[11].data, 16,
" ** **");
78 "desired width of test image").asInt32();
80 "desired height of test image").asInt32();
81 horizontalFov=config.
check(
"horizontalFov",
Value(1.0),
82 "desired horizontal fov of test image").asFloat64();
83 verticalFov=config.
check(
"verticalFov",
Value(2.0),
84 "desired vertical fov of test image").asFloat64();
86 "mirroring disabled by default").asBool();
87 intrinsic.put(
"physFocalLength",config.
check(
"physFocalLength",
Value(3.0),
"Physical focal length of the fakeFrameGrabber").asFloat64());
88 intrinsic.put(
"focalLengthX",config.
check(
"focalLengthX",
Value(4.0),
"Horizontal component of the focal length of the fakeFrameGrabber").asFloat64());
89 intrinsic.put(
"focalLengthY",config.
check(
"focalLengthY",
Value(5.0),
"Vertical component of the focal length of the fakeFrameGrabber").asFloat64());
90 intrinsic.put(
"principalPointX",config.
check(
"principalPointX",
Value(6.0),
"X coordinate of the principal point of the fakeFrameGrabber").asFloat64());
91 intrinsic.put(
"principalPointY",config.
check(
"principalPointY",
Value(7.0),
"Y coordinate of the principal point of the fakeFrameGrabber").asFloat64());
92 intrinsic.put(
"retificationMatrix",config.
check(
"retificationMatrix",*retM,
"Matrix that describes the lens' distortion(fake)"));
93 intrinsic.put(
"distortionModel",config.
check(
"distortionModel",
Value(
"FishEye"),
"Reference to group of parameters describing the distortion model of the camera").asString());
94 intrinsic.put(
"k1",config.
check(
"k1",
Value(8.0),
"Radial distortion coefficient of the lens(fake)").asFloat64());
95 intrinsic.put(
"k2",config.
check(
"k2",
Value(9.0),
"Radial distortion coefficient of the lens(fake)").asFloat64());
96 intrinsic.put(
"k3",config.
check(
"k3",
Value(10.0),
"Radial distortion coefficient of the lens(fake)").asFloat64());
97 intrinsic.put(
"t1",config.
check(
"t1",
Value(11.0),
"Tangential distortion of the lens(fake)").asFloat64());
98 intrinsic.put(
"t2",config.
check(
"t2",
Value(12.0),
"Tangential distortion of the lens(fake)").asFloat64());
104 configurations.push_back(conf1);
105 configurations.push_back(conf2);
106 configurations.push_back(conf3);
109 if (config.
check(
"freq",val,
"rate of test images in Hz")) {
112 }
else if (config.
check(
"period",val,
113 "period of test images in seconds")) {
120 mode = config.
check(
"mode",
122 "bouncy [ball], scrolly [line], grid [grid], grid multisize [size], random [rand], none [none], time test[time]").asVocab();
124 if (config.
check(
"src")) {
128 "background image to use, if any").asString())) {
131 if (background.width()>0) {
132 w = background.width();
133 h = background.height();
137 use_bayer = config.
check(
"bayer",
"should emit bayer test image?");
138 use_mono = config.
check(
"mono",
"should emit a monochrome image?");
139 use_mono = use_mono||use_bayer;
143 "Test grabber period %g / freq %g , mode [%s]",
149 "Test grabber period %g / freq [inf], mode [%s]",
166 double dt = period-(
now-prev);
194 configurations=this->configurations;
211 horizontalFov=this->horizontalFov;
212 verticalFov=this->verticalFov;
217 this->horizontalFov=horizontalFov;
218 this->verticalFov=verticalFov;
223 intrinsic=this->intrinsic;
238 createTestImage(image);
245 createTestImage(rgb_image);
247 makeSimpleBayer(rgb_image,image);
249 image.copy(rgb_image);
283 void FakeFrameGrabber::printTime(
unsigned char* pixbuf,
int pixbuf_w,
int pixbuf_h,
int x,
int y,
char* s,
int size)
286 for (
int i = 0; i<size; i++)
288 char* num_p =
nullptr;
291 case '0': num_p = num[0].data;
break;
292 case '1': num_p = num[1].data;
break;
293 case '2': num_p = num[2].data;
break;
294 case '3': num_p = num[3].data;
break;
295 case '4': num_p = num[4].data;
break;
296 case '5': num_p = num[5].data;
break;
297 case '6': num_p = num[6].data;
break;
298 case '7': num_p = num[7].data;
break;
299 case '8': num_p = num[8].data;
break;
300 case '9': num_p = num[9].data;
break;
301 case ' ': num_p = num[10].data;
break;
302 case '.': num_p = num[11].data;
break;
305 for (
int yi = 0; yi<5; yi++)
306 for (
int xi = 0; xi<3; xi++)
308 int ii = yi * 3 + xi;
309 if (num_p[ii] ==
'*')
311 for (
int r = yi * pixelsize; r<yi*pixelsize + pixelsize; r++)
313 int off = i * (pixelsize + 20);
314 for (
int c = xi * pixelsize + off; c<xi*pixelsize + pixelsize + off; c++)
322 unsigned char *pixel = pixbuf;
323 size_t offset = c * 3 + r * (pixbuf_w * 3);
324 pixel = pixel + offset;
339 t -= ((
t*1000)-(
int)
t)/1000;
342 if (background.width()>0) {
343 image.copy(background);
353 std::snprintf(txtbuf, 50,
"%.3f", time);
354 int len = strlen(txtbuf);
357 printTime((
unsigned char*)image.getRawImage(), image.width(), image.height(), 0, 0, txtbuf, len);
368 int delta_x = (rnd % 5) - 2;
372 int delta_y = (rnd % 5) - 2;
386 size_t ww = image.width();
387 size_t hh = image.height();
389 for (
size_t x=0; x<ww; x++) {
390 for (
size_t y=0; y<hh; y++) {
391 double xx = ((double)x)/(ww-1);
392 double yy = ((double)y)/(hh-1);
394 auto r =
static_cast<unsigned char>(0.5 + 255 * xx);
395 auto g =
static_cast<unsigned char>(0.5 + 255 * yy);
396 auto b =
static_cast<unsigned char>(act * 255);
403 case VOCAB_GRID_MULTISIZE:
405 static int count = 0;
409 yCDebug(FAKEFRAMEGRABBER) <<
"size 100, 100";
410 image.resize(100,100);
412 else if (count == 200)
414 yCDebug(FAKEFRAMEGRABBER) <<
"size 200, 100";
415 image.resize(200, 100);
417 else if (count == 300)
419 yCDebug(FAKEFRAMEGRABBER) <<
"size 300, 50";
420 image.resize(300, 50);
424 size_t ww = w = image.width();
425 size_t hh = h = image.height();
427 for (
size_t x = 0; x<ww; x++) {
428 for (
size_t y = 0; y<hh; y++) {
429 double xx = ((double)x) / (ww - 1);
430 double yy = ((double)y) / (hh - 1);
431 bool act = (y == ct);
432 auto r =
static_cast<unsigned char>(0.5 + 255 * xx);
433 auto g =
static_cast<unsigned char>(0.5 + 255 * yy);
434 auto b =
static_cast<unsigned char>(act * 255);
444 for (
size_t i=0; i<image.width(); i++) {
445 image.
pixel(i,ct).
r = 255;
448 std::snprintf(ttxt, 50,
"%021.10f",
t);
449 image.
pixel(0, 0).
r = ttxt[0] -
'0';
450 image.
pixel(0, 0).
g = ttxt[1] -
'0';
451 image.
pixel(0, 0).
b = ttxt[2] -
'0';
453 image.
pixel(1, 0).
r = ttxt[3] -
'0';
454 image.
pixel(1, 0).
g = ttxt[4] -
'0';
455 image.
pixel(1, 0).
b = ttxt[5] -
'0';
457 image.
pixel(2, 0).
r = ttxt[6] -
'0';
458 image.
pixel(2, 0).
g = ttxt[7] -
'0';
459 image.
pixel(2, 0).
b = ttxt[8] -
'0';
461 image.
pixel(3, 0).
r = ttxt[9] -
'0';
462 image.
pixel(3, 0).
g = ttxt[10] -
'0';
463 image.
pixel(3, 0).
b = ttxt[11] -
'0';
465 image.
pixel(4, 0).
r = ttxt[12] -
'0';
466 image.
pixel(4, 0).
g = ttxt[13] -
'0';
467 image.
pixel(4, 0).
b = ttxt[14] -
'0';
469 image.
pixel(5, 0).
r = ttxt[15] -
'0';
470 image.
pixel(5, 0).
g = ttxt[16] -
'0';
471 image.
pixel(5, 0).
b = ttxt[17] -
'0';
473 image.
pixel(6, 0).
r = ttxt[18] -
'0';
474 image.
pixel(6, 0).
g = ttxt[19] -
'0';
475 image.
pixel(6, 0).
b = ttxt[20] -
'0';
482 static unsigned char r=128,g=128,b=128;
484 size_t ww = image.width();
485 size_t hh = image.height();
489 std::uniform_real_distribution<double> udist(-1.0, 1.0);
490 for (
size_t x=0; x<ww; x++) {
491 for (
size_t y=0; y<hh; y++) {
508 if (ct>=image.height()) {
511 if (by>=image.height()) {
512 by = image.height()-1;
514 if (bx>=image.width()) {
515 bx = image.width()-1;
525 bool FakeFrameGrabber::makeSimpleBayer(
529 bayer.resize(img.width(), img.height());
531 const size_t w = img.width();
532 const size_t h = img.height();
535 for (i = 0; i < h; i++) {
536 auto* row = (
PixelRgb *)img.getRow(i);
539 for (j = 0; j < w; j++) {
580 yCWarning(FAKEFRAMEGRABBER,
"'test_grabber' was renamed 'fakeFrameGrabber'. The old name is still supported for compatibility, but it will be deprecated and removed in a future release. Please update your scripts");
bool setRgbFOV(double horizontalFov, double verticalFov) override
Set the field of view (FOV) of the rgb camera.
bool hasAuto(int feature, bool *hasAuto) override
Check if the requested feature has the 'auto' mode.
int height() const override
Return the height of each frame.
constexpr yarp::conf::vocab32_t createVocab(char a, char b=0, char c=0, char d=0)
bool hasOnOff(int feature, bool *HasOnOff) override
Check if the camera has the ability to turn on/off the requested feature.
int getRgbWidth() override
Return the width of each frame.
A base class for nested structures that can be searched.
bool read(ImageOf< PixelRgb > &dest, const std::string &src, image_fileformat format=FORMAT_ANY)
static Value * makeList()
Create a list Value.
bool setRgbMirroring(bool mirror) override
Set the mirroring setting of the sensor.
bool setFeature(int feature, double value) override
Set the requested feature to a value (saturation, brightness ...
#define yCWarning(component,...)
std::default_random_engine randengine
bool hasOnePush(int feature, bool *hasOnePush) override
Check if the requested feature has the 'onePush' mode.
bool getImage(yarp::sig::ImageOf< yarp::sig::PixelRgb > &image) override
Get an rgb image from the frame grabber, if required demosaicking/color reconstruction is applied.
#define YARP_LOG_COMPONENT(name,...)
bool hasFeature(int feature, bool *hasFeature) override
Check if camera has the requested feature (saturation, brightness ...
bool open(yarp::os::Searchable &config) override
Configure with a set of options.
double now()
Return the current time in seconds, relative to an arbitrary starting point.
An interface for the device drivers.
std::string decode(NetInt32 code)
Convert a vocabulary identifier into a string.
unsigned char PixelMono
Monochrome pixel type.
bool setActive(int feature, bool onoff) override
Set the requested feature on or off.
bool hasManual(int feature, bool *hasManual) override
Check if the requested feature has the 'manual' mode.
bool getCameraDescription(CameraDescriptor *camera) override
Get a basic description of the camera hw.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
bool open(yarp::os::Searchable &config) override
Configure with a set of options.
bool getRgbResolution(int &width, int &height) override
Get the resolution of the rgb image from the camera.
bool close() override
Close the DeviceDriver.
bool getRgbIntrinsicParam(yarp::os::Property &intrinsic) override
Get the intrinsic parameters of the rgb camera.
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 ...
Very basic drawing functions, in case you don't have anything better available.
fakeFrameGrabber: A fake camera for testing.
T & pixel(size_t x, size_t y)
bool hasRawVideo() override
An abstraction for a time stamp and/or sequence number.
bool getActive(int feature, bool *isActive) override
Get the current status of the feature, on or off.
Struct describing a possible camera configuration.
#define yCInfo(component,...)
An interface to the operating system, including Port based communication.
#define yCDebug(component,...)
bool setMode(int feature, FeatureMode mode) override
Set the requested mode for the feature.
bool getRgbSupportedConfigurations(yarp::sig::VectorOf< yarp::dev::CameraConfig > &configurations) override
Get the possible configurations of the camera.
The main, catch-all namespace for YARP.
void addCircle(ImageOf< T > &dest, const T &pix, int i, int j, int r)
bool getFeature(int feature, double *value) override
Get the current value for the requested feature.
int getRgbHeight() override
Return the height of each frame.
int width() const override
Return the width of each frame.
bool getRgbMirroring(bool &mirror) override
Get the mirroring setting of the sensor.
bool getRgbFOV(double &horizontalFov, double &verticalFov) override
Get the field of view (FOV) of the rgb camera.
YarpVocabPixelTypesEnum pixelCoding
bool setRgbResolution(int width, int height) override
Set the resolution of the rgb image from the camera.
bool getMode(int feature, FeatureMode *mode) override
Get the current mode for the feature.
A single value (typically within a Bottle).
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
void delay(double seconds)
Wait for a certain number of seconds.
A class for storing options and configuration information.
constexpr yarp::conf::vocab32_t VOCAB_LINE