Fawkes API  Fawkes Development Version
color_train_widget.h
1 
2 /***************************************************************************
3  * color_train_widget.h - Color training widget
4  *
5  * Created: Thu Mar 20 20:53:35 2008
6  * Copyright 2006 Daniel Beck
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #ifndef _FIREVISION_TOOLS_FIRESTATION_COLOR_TRAIN_WIDGET_H_
24 #define _FIREVISION_TOOLS_FIRESTATION_COLOR_TRAIN_WIDGET_H_
25 
26 #include <fvutils/base/roi.h>
27 #include <fvutils/color/colorspaces.h>
28 
29 #include <gtkmm.h>
30 #include <memory>
31 
33 namespace firevision {
34 class BayesColormapGenerator;
35 class Zauberstab;
36 class YuvColormap;
37 } // namespace firevision
38 
40 {
41 public:
42  static const unsigned int MOUSE_BUTTON_LEFT = 1; /**< constant for left mouse button id */
43  static const unsigned int MOUSE_BUTTON_RIGHT = 3; /**< constant for right mouse button id */
44 
45  ColorTrainWidget(Gtk::Window *parent);
46  virtual ~ColorTrainWidget();
47 
48  void set_fg_object(firevision::hint_t fg_object);
49 
50  void set_src_buffer(unsigned char *buffer, unsigned int img_width, unsigned int img_height);
51  void set_draw_buffer(unsigned char *buffer);
52 
53  void click(unsigned int x, unsigned int y, unsigned int button = MOUSE_BUTTON_LEFT);
54  void reset_selection();
55 
56  void load_histograms();
57  void save_histograms();
58 
59  void add_to_colormap();
60  void reset_colormap();
61  void load_colormap();
62  void save_colormap();
64 
66 
67  void set_reset_selection_btn(Gtk::Button *btn);
68  void set_add_to_colormap_btn(Gtk::Button *btn);
69  void set_reset_colormap_btn(Gtk::Button *btn);
70  void set_load_histos_btn(Gtk::Button *btn);
71  void set_save_histos_btn(Gtk::Button *btn);
72  void set_load_colormap_btn(Gtk::Button *btn);
73  void set_save_colormap_btn(Gtk::Button *btn);
74  void set_colormap_img(Gtk::Image *img);
75  void set_segmentation_img(Gtk::Image *img);
76  void set_threshold_scl(Gtk::Scale *scl);
77  void set_min_prob_scl(Gtk::Scale *scl);
78  void set_filechooser_dlg(Gtk::FileChooserDialog *dlg);
79  void set_cm_layer_selector(Gtk::Scale *scl);
80  void
81  set_cm_selector(Gtk::SpinButton *depth, Gtk::SpinButton *width = 0, Gtk::SpinButton *height = 0);
82 
83  Glib::Dispatcher &update_image();
84  Glib::Dispatcher &colormap_updated();
85 
86 private:
87  void resize_seg_image(Gtk::Allocation &allocation);
88  bool set_threshold(Gtk::ScrollType scroll, double value);
89  bool set_min_prob(Gtk::ScrollType scroll, double value);
90  static void free_rgb_buffer(const guint8 *rgb_buffer);
91 
92  void reset_gui();
93 
95  std::shared_ptr<firevision::Zauberstab> m_zauberstab;
96  std::shared_ptr<ColormapViewerWidget> m_cvw;
97 
98  firevision::hint_t m_fg_object;
99 
100  unsigned char * m_src_buffer;
101  unsigned char * m_draw_buffer;
102  unsigned int m_img_width;
103  unsigned int m_img_height;
104  unsigned int m_img_size;
105  firevision::colorspace_t m_img_cs;
106  unsigned int m_seg_img_max_width;
107  unsigned int m_seg_img_max_height;
108 
109  Gtk::Window * m_wnd_parent;
110  Gtk::Button * m_btn_reset_selection;
111  Gtk::Button * m_btn_add_to_colormap;
112  Gtk::Button * m_btn_reset_colormap;
113  Gtk::Button * m_btn_load_histos;
114  Gtk::Button * m_btn_save_histos;
115  Gtk::Button * m_btn_load_colormap;
116  Gtk::Button * m_btn_save_colormap;
117  Gtk::SpinButton * m_spbtn_cm_depth;
118  Gtk::SpinButton * m_spbtn_cm_width;
119  Gtk::SpinButton * m_spbtn_cm_height;
120  Gtk::Image * m_img_segmentation;
121  Gtk::Scale * m_scl_threshold;
122  Gtk::Scale * m_scl_min_prob;
123  Gtk::FileChooserDialog *m_fcd_filechooser;
124 
125  Glib::Dispatcher m_signal_update_image;
126  Glib::Dispatcher m_signal_colormap_updated;
127 };
128 
129 #endif /* FIREVISION_TOOLS_FIRESTATION_COLOR_TRAIN_WIDGET_H__ */
This widget implements the complete color training process.
void draw_segmentation_result()
Render the result of segmenting the image in the source buffer considering the current colormap into ...
void set_cm_layer_selector(Gtk::Scale *scl)
Set the widget to choose the layer of the colormap to display.
ColorTrainWidget(Gtk::Window *parent)
Constructor.
void set_draw_buffer(unsigned char *buffer)
Set the buffer to draw the selection into.
void set_filechooser_dlg(Gtk::FileChooserDialog *dlg)
Set the filechooser dialog to be used by this widget.
void click(unsigned int x, unsigned int y, unsigned int button=MOUSE_BUTTON_LEFT)
The user clicked into the image.
void load_histograms()
Open a dialog to load a histogram.
void add_to_colormap()
Generate a new colormap by adding the current histograms.
Glib::Dispatcher & update_image()
Access the signal that is emitted whenever a redraw of the image is necessary.
void set_colormap_img(Gtk::Image *img)
Set the image to render the colormap into.
void set_save_histos_btn(Gtk::Button *btn)
Set the buffon to open a dialog to save histograms.
void set_save_colormap_btn(Gtk::Button *btn)
Set the buffon to open a dialog to save a colormap.
void set_reset_selection_btn(Gtk::Button *btn)
Set the button to reset the selection.
static const unsigned int MOUSE_BUTTON_RIGHT
constant for right mouse button id
void set_segmentation_img(Gtk::Image *img)
Set the image to render the segmented image into.
void set_min_prob_scl(Gtk::Scale *scl)
Set the scale to control the minimum probability.
void set_threshold_scl(Gtk::Scale *scl)
Set the scale to control the selection threshold.
void set_src_buffer(unsigned char *buffer, unsigned int img_width, unsigned int img_height)
Set the buffer containing the image data.
static const unsigned int MOUSE_BUTTON_LEFT
constant for left mouse button id
void reset_selection()
Reset the selection.
void set_load_histos_btn(Gtk::Button *btn)
Set the buffon to open a dialog to load histograms.
void set_fg_object(firevision::hint_t fg_object)
Set the current foreground object.
virtual ~ColorTrainWidget()
Destructor.
void reset_colormap()
Reset the colormap.
firevision::YuvColormap * get_colormap() const
Get the current colormap.
void set_load_colormap_btn(Gtk::Button *btn)
Set the buffon to open a dialog to load a colormap.
void set_cm_selector(Gtk::SpinButton *depth, Gtk::SpinButton *width=0, Gtk::SpinButton *height=0)
Set the widget to adjust the depth of the colormap.
void save_histograms()
Open a dialog to save a histogram.
void set_reset_colormap_btn(Gtk::Button *btn)
Set the button to reset the colormap.
void load_colormap()
Open a dialog to load a colormap.
void save_colormap()
Open a dialog to save a colormap.
Glib::Dispatcher & colormap_updated()
Access the signal that is emitted whenever the colormap has changed.
void set_add_to_colormap_btn(Gtk::Button *btn)
Set the button to trigger the generation of the colormap.
Select a layer from a colormap and render it to a Gtk::Image.
Colormap Generator using Bayes method.
YUV Colormap.
Definition: yuvcm.h:36