131 reply.
addString(
"set_image <file_name>/off");
132 reply.
addString(
"available modes: ball, line, grid, size, rand, none, time");
184 reply.
addString(
"Unknown command. Type 'help'.");
215 m_intrinsic.
put(
"rectificationMatrix",val);
227 conf1.framerate=60.0;
234 conf2.framerate=30.0;
241 conf3.framerate=15.0;
266 if (background.
width()>0)
282 "Test grabber period %g / freq %g , mode %s",
290 for (
auto&
buff : buffs) {
299 yCError(
FAKEFRAMEGRABBER,
"If yes, use the `fakeFrameGrabber_rpc_port` parameter to set a different name for each of them");
344 configurations=this->configurations;
373 intrinsic=this->m_intrinsic;
391 std::unique_lock<std::mutex>
lk(mutex[
i]);
392 createTestImage(buffs[
i], buff_ts[
i]);
396 curr_buff_mutex.lock();
398 curr_buff_mutex.unlock();
399 std::this_thread::yield();
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]);});
406 img_ready[
i] =
false;
407 img_consumed[
i] =
false;
408 createTestImage(buffs[
i], buff_ts[
i]);
410 img_ready_cv[
i].notify_all();
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();
425 img_ready_cv[
i].notify_all();
438 curr_buff_mutex.lock();
439 size_t cb = curr_buff;
440 std::unique_lock<std::mutex>
lk(mutex[
cb]);
443 curr_buff_mutex.unlock();
447 curr_buff_mutex.lock();
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]);});
458 img_consumed[
cb] =
true;
459 img_consumed_cv[
cb].notify_one();
461 curr_buff = (
cb + 1) % 2;
462 curr_buff_mutex.unlock();
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();
480 makeSimpleBayer(buffs[
cb], image);
486 curr_buff_mutex.lock();
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]);});
495 makeSimpleBayer(buffs[
cb], image);
500 img_consumed[
cb] =
true;
501 img_consumed_cv[
cb].notify_one();
503 curr_buff = (
cb + 1) % 2;
504 curr_buff_mutex.unlock();
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)
556 for (
size_t i = 0;
i < size;
i++)
558 const char*
num_p =
nullptr;
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;
604 t -= (((
t*1000) -
static_cast<int64_t>(
t*1000)) / 1000);
613 image.
copy(background);
620 std::snprintf(
txtbuf, 50,
"%.3f", time);
628 else if (
m_mode ==
"[ball]")
632 image.
copy(background);
636 addCircle(image,PixelRgb{0,255,0},bx,by,15);
637 addCircle(image,PixelRgb{0,255,255},bx,by,8);
657 else if (
m_mode ==
"[grid]")
663 for (
size_t x=0; x<
ww; x++) {
664 for (
size_t y=0; y<
hh; y++) {
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};
677 else if (
m_mode ==
"[size]")
679 static int count = 0;
686 else if (count == 200)
691 else if (count == 300)
701 for (
size_t x = 0; x<
ww; x++) {
702 for (
size_t y = 0; y<
hh; y++) {
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};
714 else if (
m_mode ==
"[line]")
718 image.
copy(background);
722 for (
size_t i=0;
i<image.
width();
i++) {
723 image.
pixel(
i,ct).r = 255;
727 else if (
m_mode ==
"[rand]")
730 static unsigned char r = 128;
731 static unsigned char g = 128;
732 static unsigned char b = 128;
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};
749 else if (
m_mode ==
"[none]")
753 image.
copy(background);
771 if (bx>=image.
width()) {
772 bx = image.
width()-1;
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 {
791 std::snprintf(
ttxt, 50,
"%021.10f", timestamp);
828bool FakeFrameGrabber::makeSimpleBayer(
832 bayer.resize(img.width(), img.height());
834 const size_t w = img.width();
835 const size_t h = img.height();
838 for (
i = 0;
i < h;
i++) {
839 auto*
row = (PixelRgb *)img.getRow(
i);
842 for (
j = 0;
j < w;
j++) {
std::string m_fakeFrameGrabber_rpc_port
std::string m_distortionModel
std::vector< double > m_rectificationMatrix
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 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 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.
void addVocab32(yarp::conf::vocab32_t x)
Places a vocabulary item in the bottle, at the end of the list.
bool read(ConnectionReader &reader) override
Set the bottle's value based on input from a network connection.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
void clear()
Empties the bottle of any objects it contains.
bool write(ConnectionWriter &writer) const override
Output a representation of the bottle to a network connection.
void addString(const char *str)
Places a string in the bottle, at the end of the list.
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.
void close() override
Stop port activity.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
A class for storing options and configuration information.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
A base class for nested structures that can be searched.
An abstraction for a time stamp and/or sequence number.
void update()
Set the timestamp to the current time, and increment the sequence number (wrapping to 0 if the sequen...
bool stop()
Stop the thread.
bool isStopping()
Returns true if the thread is stopping (Thread::stop has been called).
bool isRunning()
Returns true if the thread is running (Thread::start has been called successfully and the thread has ...
bool start()
Start the new thread running.
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.
virtual Bottle * asList() const
Get list value.
virtual std::string asString() const
Get string 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.
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.
void push_back(const T &elem)
Push a new element in the vector: size is changed.
#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)
For streams capable of holding different kinds of content, check what they actually have.
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.
An interface to the operating system, including Port based communication.
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)
Struct describing a possible camera configuration.