23 #include "retriever_thread.h" 25 #include <fvcams/camera.h> 26 #include <fvmodels/color/lookuptable.h> 27 #include <fvutils/ipc/shm_image.h> 28 #include <fvutils/writers/jpeg.h> 29 #include <fvutils/writers/seq_writer.h> 30 #include <utils/time/tracker.h> 36 using namespace firevision;
51 const std::string &cfg_name,
52 const std::string &cfg_prefix)
53 :
Thread(
"FvRetrieverThread",
Thread::OPMODE_WAITFORWAKEUP),
56 cfg_prefix_(cfg_prefix),
57 camera_string_(camera_string),
60 set_name(
"FvRetrieverThread_%s", cfg_name_.c_str());
72 colorspace_t cspace = YUV422_PLANAR;
73 std::string cspace_str = colorspace_to_string(cspace);
76 cspace = colorspace_by_name(cspace_str.c_str());
79 if (cspace == CS_UNKNOWN) {
80 throw Exception(
"Unknown colorspace '%s' configured", cspace_str.c_str());
85 "Registering for camera '%s' (colorspace %s)",
86 camera_string_.c_str(),
87 colorspace_to_string(cspace));
90 e.
append(
"FvRetrieverThread::init() failed");
95 if (asprintf(&imgbufname,
"retriever_%s", cfg_name_.c_str()) == -1) {
96 throw Exception(
"Cannot allocate buffer name");
105 throw Exception(
"Shared memory segment not valid");
125 std::string save_path;
129 save_path = (
"recorded_images");
132 seq_writer->
set_path(save_path.c_str());
144 ttc_capture_ = tt_->
add_class(
"Capture");
146 ttc_dispose_ = tt_->
add_class(
"Dispose");
155 for (
unsigned int u = 100; u < 150; ++u) {
156 for (
unsigned int v = 100; v < 150; ++v) {
157 ycm->
set(128, u, v, C_ORANGE);
161 cam_has_timestamp_support_ =
true;
169 cam_has_timestamp_support_ =
false;
201 if (cam_has_timestamp_support_)
206 if ((++loop_count_ % 200) == 0) {
216 if (cam_has_timestamp_support_) {
virtual unsigned int buffer_size()=0
Size of buffer.
void ping_start(unsigned int cls)
Start of given class task.
virtual void init()
Initialize the thread.
FvRetrieverThread(const std::string &camera_string, const std::string &cfg_name, const std::string &cfg_prefix)
Constructor.
virtual void log_info(const char *component, const char *format,...)=0
Log informational message.
void lock_for_write()
Lock shared memory segment for writing.
Fawkes library namespace.
Interface to write images.
virtual bool get_bool(const char *path)=0
Get value from configuration which is of type bool.
firevision::VisionMaster * vision_master
Vision master.
virtual ~FvRetrieverThread()
Destructor.
Called method has not been implemented.
virtual unsigned int pixel_width()=0
Width of image in pixels.
A class for handling time.
Color model based on a lookup table.
Thread class encapsulation of pthreads.
virtual colorspace_t colorspace()=0
Colorspace of returned image.
Logger * logger
This is the Logger member used to access the logger.
YuvColormap * get_colormap() const
Get colormap.
bool is_valid() const
Check validity of shared memory segment.
virtual void unregister_thread(fawkes::Thread *thread)=0
Unregister a thread.
unsigned char * buffer() const
Get image buffer.
Clock * clock
By means of this member access to the clock is given.
void set_colorspace(colorspace_t cspace)
Set the colorspace of the image.
Writes a sequence of images to disk.
void set_name(const char *format,...)
Set name of thread.
Base class for exceptions in Fawkes.
virtual void capture()=0
Capture an image.
virtual fawkes::Time * capture_time()
Get the Time of the last successfully captured image.
Thread aspect to use in FireVision apps.
void set_frame_id(const char *frame_id)
Set frame ID.
virtual void set(unsigned int y, unsigned int u, unsigned int v, color_t c)
Set color class for given YUV value.
unsigned int add_class(std::string name)
Add a new class.
Shared memory image buffer.
bool is_zero() const
Check if time is zero.
const char * name() const
Get name of thread.
void set_dimensions(unsigned int width, unsigned int height)
Set the image dimensions.
void ping_end(unsigned int cls)
End of given class task.
void print_to_stdout()
Print results to stdout.
virtual void log_debug(const char *component, const char *format,...)=0
Log debug message.
virtual unsigned char * buffer()=0
Get access to current image buffer.
virtual unsigned int pixel_height()=0
Height of image in pixels.
Time & stamp()
Set this time to the current time.
void write(unsigned char *buffer)
Write a single image to disk.
void set_path(const char *img_path)
Set the path to where the images are stored.
virtual void loop()
Thread loop.
virtual Camera * register_for_camera(const char *camera_string, fawkes::Thread *thread, colorspace_t cspace=YUV422_PLANAR)=0
Register thread for camera.
Configuration * config
This is the Configuration member used to access the configuration.
virtual void finalize()
Finalize the thread.
void set_capture_time(fawkes::Time *time)
Set the capture time.
void unlock()
Unlock memory.
void append(const char *format,...)
Append messages to the message list.
virtual std::string get_string(const char *path)=0
Get value from configuration which is of type string.
virtual void dispose_buffer()=0
Dispose current buffer.