35 constexpr
char num[12][16]
121 constexpr
size_t num_width = 3;
122 constexpr
size_t num_height = 5;
133 "desired width of test image").asInt32();
135 "desired height of test image").asInt32();
136 horizontalFov=config.
check(
"horizontalFov",
Value(1.0),
137 "desired horizontal fov of test image").asFloat64();
138 verticalFov=config.
check(
"verticalFov",
Value(2.0),
139 "desired vertical fov of test image").asFloat64();
141 "mirroring disabled by default").asBool();
142 intrinsic.put(
"physFocalLength",config.
check(
"physFocalLength",
Value(3.0),
"Physical focal length of the fakeFrameGrabber").asFloat64());
143 intrinsic.put(
"focalLengthX",config.
check(
"focalLengthX",
Value(4.0),
"Horizontal component of the focal length of the fakeFrameGrabber").asFloat64());
144 intrinsic.put(
"focalLengthY",config.
check(
"focalLengthY",
Value(5.0),
"Vertical component of the focal length of the fakeFrameGrabber").asFloat64());
145 intrinsic.put(
"principalPointX",config.
check(
"principalPointX",
Value(6.0),
"X coordinate of the principal point of the fakeFrameGrabber").asFloat64());
146 intrinsic.put(
"principalPointY",config.
check(
"principalPointY",
Value(7.0),
"Y coordinate of the principal point of the fakeFrameGrabber").asFloat64());
150 intrinsic.put(
"retificationMatrix",config.
check(
"retificationMatrix",*retM,
"Matrix that describes the lens' distortion(fake)"));
153 intrinsic.put(
"distortionModel",config.
check(
"distortionModel",
Value(
"FishEye"),
"Reference to group of parameters describing the distortion model of the camera").asString());
154 intrinsic.put(
"k1",config.
check(
"k1",
Value(8.0),
"Radial distortion coefficient of the lens(fake)").asFloat64());
155 intrinsic.put(
"k2",config.
check(
"k2",
Value(9.0),
"Radial distortion coefficient of the lens(fake)").asFloat64());
156 intrinsic.put(
"k3",config.
check(
"k3",
Value(10.0),
"Radial distortion coefficient of the lens(fake)").asFloat64());
157 intrinsic.put(
"t1",config.
check(
"t1",
Value(11.0),
"Tangential distortion of the lens(fake)").asFloat64());
158 intrinsic.put(
"t2",config.
check(
"t2",
Value(12.0),
"Tangential distortion of the lens(fake)").asFloat64());
165 configurations.push_back(conf1);
172 configurations.push_back(conf2);
179 configurations.push_back(conf3);
182 if (config.
check(
"freq", val,
"rate of test images in Hz")) {
185 }
else if (config.
check(
"period", val,
186 "period of test images in seconds")) {
194 mode = config.
check(
"mode",
196 "bouncy [ball], scrolly [line], grid [grid], grid multisize [size], random [rand], none [none], time test[time]").asVocab();
198 if (config.
check(
"src")) {
202 "background image to use, if any").asString())) {
205 if (background.width()>0) {
206 if (config.
check(
"width") || config.
check(
"height")) {
207 yCWarning(FAKEFRAMEGRABBER,
"width and height option are ignored when passing a background image");
209 w = background.width();
210 h = background.height();
215 use_bayer = config.
check(
"bayer",
"should emit bayer test image?");
216 use_mono = config.
check(
"mono",
"should emit a monochrome image?");
217 use_mono = use_mono||use_bayer;
221 "Test grabber period %g / freq %g , mode [%s]",
227 "Test grabber period %g / freq [inf], mode [%s]",
244 double dt = period-(
now-prev);
272 configurations=this->configurations;
289 horizontalFov=this->horizontalFov;
290 verticalFov=this->verticalFov;
295 this->horizontalFov=horizontalFov;
296 this->verticalFov=verticalFov;
301 intrinsic=this->intrinsic;
316 createTestImage(image);
323 createTestImage(rgb_image);
325 makeSimpleBayer(rgb_image,image);
327 image.
copy(rgb_image);
361 void FakeFrameGrabber::printTime(
unsigned char* pixbuf,
size_t pixbuf_w,
size_t pixbuf_h,
size_t x,
size_t y,
char* s,
size_t size)
363 for (
size_t i = 0; i < size; i++)
365 const char* num_p =
nullptr;
367 case '0': num_p = num[0];
break;
368 case '1': num_p = num[1];
break;
369 case '2': num_p = num[2];
break;
370 case '3': num_p = num[3];
break;
371 case '4': num_p = num[4];
break;
372 case '5': num_p = num[5];
break;
373 case '6': num_p = num[6];
break;
374 case '7': num_p = num[7];
break;
375 case '8': num_p = num[8];
break;
376 case '9': num_p = num[9];
break;
377 case ' ': num_p = num[10];
break;
378 case '.': num_p = num[11];
break;
379 default: num_p = num[10];
break;
382 for (
size_t yi = 0; yi < num_height; yi++)
383 for (
size_t xi = 0; xi < num_width; xi++) {
384 size_t ii = yi * num_width + xi;
385 if (num_p[ii] ==
'*') {
386 for (
size_t r = yi * num_height; r < yi*num_height + num_height; r++) {
387 size_t off = i * (num_height + 20);
388 for (
size_t c = xi * num_height + off; c < xi*num_height + num_height + off; c++) {
389 if (c >= pixbuf_h || r >= pixbuf_w) {
393 unsigned char *pixel = pixbuf;
395 pixel = pixel + offset;
410 t -= (((
t*1000) -
static_cast<int64_t
>(
t*1000)) / 1000);
419 image.
copy(background);
424 static const double start_time =
t;
425 double time =
t - start_time;
426 std::snprintf(txtbuf, 50,
"%.3f", time);
427 int len = strlen(txtbuf);
437 image.
copy(background);
446 int delta_x = (rnd % 5) - 2;
450 int delta_y = (rnd % 5) - 2;
464 size_t ww = image.
width();
465 size_t hh = image.
height();
467 for (
size_t x=0; x<ww; x++) {
468 for (
size_t y=0; y<hh; y++) {
469 double xx = ((double)x)/(ww-1);
470 double yy = ((double)y)/(hh-1);
472 auto r =
static_cast<unsigned char>(0.5 + 255 * xx);
473 auto g =
static_cast<unsigned char>(0.5 + 255 * yy);
474 auto b =
static_cast<unsigned char>(act * 255);
481 case VOCAB_GRID_MULTISIZE:
483 static int count = 0;
487 yCDebug(FAKEFRAMEGRABBER) <<
"size 100, 100";
490 else if (count == 200)
492 yCDebug(FAKEFRAMEGRABBER) <<
"size 200, 100";
495 else if (count == 300)
497 yCDebug(FAKEFRAMEGRABBER) <<
"size 300, 50";
502 size_t ww = w = image.
width();
503 size_t hh = h = image.
height();
505 for (
size_t x = 0; x<ww; x++) {
506 for (
size_t y = 0; y<hh; y++) {
507 double xx = ((double)x) / (ww - 1);
508 double yy = ((double)y) / (hh - 1);
509 bool act = (y == ct);
510 auto r =
static_cast<unsigned char>(0.5 + 255 * xx);
511 auto g =
static_cast<unsigned char>(0.5 + 255 * yy);
512 auto b =
static_cast<unsigned char>(act * 255);
523 image.
copy(background);
527 for (
size_t i=0; i<image.
width(); i++) {
528 image.
pixel(i,ct).
r = 255;
531 std::snprintf(ttxt, 50,
"%021.10f",
t);
532 image.
pixel(0, 0).
r = ttxt[0] -
'0';
533 image.
pixel(0, 0).
g = ttxt[1] -
'0';
534 image.
pixel(0, 0).
b = ttxt[2] -
'0';
536 image.
pixel(1, 0).
r = ttxt[3] -
'0';
537 image.
pixel(1, 0).
g = ttxt[4] -
'0';
538 image.
pixel(1, 0).
b = ttxt[5] -
'0';
540 image.
pixel(2, 0).
r = ttxt[6] -
'0';
541 image.
pixel(2, 0).
g = ttxt[7] -
'0';
542 image.
pixel(2, 0).
b = ttxt[8] -
'0';
544 image.
pixel(3, 0).
r = ttxt[9] -
'0';
545 image.
pixel(3, 0).
g = ttxt[10] -
'0';
546 image.
pixel(3, 0).
b = ttxt[11] -
'0';
548 image.
pixel(4, 0).
r = ttxt[12] -
'0';
549 image.
pixel(4, 0).
g = ttxt[13] -
'0';
550 image.
pixel(4, 0).
b = ttxt[14] -
'0';
552 image.
pixel(5, 0).
r = ttxt[15] -
'0';
553 image.
pixel(5, 0).
g = ttxt[16] -
'0';
554 image.
pixel(5, 0).
b = ttxt[17] -
'0';
556 image.
pixel(6, 0).
r = ttxt[18] -
'0';
557 image.
pixel(6, 0).
g = ttxt[19] -
'0';
558 image.
pixel(6, 0).
b = ttxt[20] -
'0';
563 static unsigned char r = 128;
564 static unsigned char g = 128;
565 static unsigned char b = 128;
567 size_t ww = image.
width();
568 size_t hh = image.
height();
571 for (
size_t x=0; x<ww; x++) {
572 for (
size_t y=0; y<hh; y++) {
585 image.
copy(background);
599 if (bx>=image.
width()) {
600 bx = image.
width()-1;
610 bool FakeFrameGrabber::makeSimpleBayer(
616 const size_t w = img.
width();
617 const size_t h = img.
height();
620 for (i = 0; i < h; i++) {
624 for (j = 0; j < w; j++) {
665 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");
std::default_random_engine randengine
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 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
Configure with a set of options.
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.
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.
bool hasRawVideo() override
bool close() override
Close the DeviceDriver.
bool open(yarp::os::Searchable &config) override
Configure with a set of options.
A class for storing options and configuration information.
A base class for nested structures that can be searched.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
An abstraction for a time stamp and/or sequence number.
A single value (typically within a Bottle).
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
static Value * makeList()
Create a list Value.
T & pixel(size_t x, size_t y)
size_t width() const
Gets width of image in pixels.
unsigned char * getRawImage() const
Access to the internal image buffer.
bool copy(const Image &alt)
Copy operator.
unsigned char * getRow(size_t r)
Get the address of a the first byte of a row in memory.
void resize(size_t imgWidth, size_t imgHeight)
Reallocate an image to be of a desired size, throwing away its current contents.
void zero()
Set all pixels to 0.
size_t height() const
Gets height of image in pixels.
#define yCInfo(component,...)
#define yCWarning(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
An interface for the device drivers.
double now()
Return the current time in seconds, relative to an arbitrary starting point.
void delay(double seconds)
Wait for a certain number of seconds.
std::string decode(NetInt32 code)
Convert a vocabulary identifier into a string.
An interface to the operating system, including Port based communication.
constexpr yarp::conf::vocab32_t createVocab(char a, char b=0, char c=0, char d=0)
Very basic drawing functions, in case you don't have anything better available.
void addCircle(ImageOf< T > &dest, const T &pix, int i, int j, int r)
bool read(ImageOf< PixelRgb > &dest, const std::string &src, image_fileformat format=FORMAT_ANY)
unsigned char PixelMono
Monochrome pixel type.
The main, catch-all namespace for YARP.
Struct describing a possible camera configuration.
YarpVocabPixelTypesEnum pixelCoding