ImageLabeler.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*
  2. * ImageLabeler.h
  3. *
  4. * Created on: Oct 4, 2011
  5. * Author: Gapchich Vladislav
  6. */
  7. #ifndef __IMAGELABELER_H__
  8. #define __IMAGELABELER_H__
  9. #include "ImageHolder.h"
  10. #include "ImageDescriptionForm.h"
  11. #include "OptionsForm.h"
  12. #include <QMainWindow>
  13. #include <QDir>
  14. /* forward declarations */
  15. class QMenuBar;
  16. class QMenu;
  17. class QAction;
  18. class QHBoxLayout;
  19. class QVBoxLayout;
  20. class QGridLayout;
  21. class QPushButton;
  22. class QPixmap;
  23. class QLabel;
  24. class QFrame;
  25. class QListWidget;
  26. class QListWidgetItem;
  27. class QButtonGroup;
  28. class QDomDocument;
  29. class QDomElement;
  30. class ImageLabeler : public QMainWindow
  31. {
  32. Q_OBJECT
  33. protected:
  34. /* events */
  35. void resizeEvent(QResizeEvent *anEvent);
  36. void mousePressEvent(QMouseEvent *anEvent);
  37. void wheelEvent(QWheelEvent *anEvent);
  38. void keyPressEvent(QKeyEvent *anEvent);
  39. void getImagesFromDir(const QDir &dir);
  40. void showWarning(const QString text);
  41. bool askForUnsavedData();
  42. void loadLegendFromNode(QDomElement *anElement);
  43. void setPolyFromData(
  44. QString *aPolyData,
  45. int *ID
  46. );
  47. void setBBoxFromData(
  48. QString *aBBoxData,
  49. int *ID
  50. );
  51. Polygon polyFromData(
  52. QString *aPolyData
  53. );
  54. Polygon polyFromString(
  55. QString *aString,
  56. int *oldID
  57. );
  58. BoundingBox BBoxFromData(
  59. QString *aBBoxData
  60. );
  61. BoundingBox BBoxFromString(
  62. QString *aString,
  63. int *oldID
  64. );
  65. void enableTools();
  66. void disableTools();
  67. void legendToXml(QDomDocument *aDoc, QDomElement *aRoot);
  68. void objectsToXml(QDomDocument *aDoc, QDomElement *aRoot);
  69. public:
  70. ImageLabeler(QWidget *aParent = 0);
  71. virtual ~ImageLabeler();
  72. public slots:
  73. void addLabel();
  74. void addLabel(
  75. int aLabelID,
  76. bool isMain,
  77. QString aLabel
  78. );
  79. void removeLabel();
  80. void setLabelID(QListWidgetItem *anItem);
  81. void addBBoxArea(
  82. int anID,
  83. BoundingBox aBBox
  84. );
  85. void addPolyArea(
  86. int aPolyID,
  87. Polygon aPoly
  88. );
  89. void deleteArea();
  90. void editArea();
  91. void toggleLabelPriority();
  92. void loadImages();
  93. void nextImage();
  94. void prevImage();
  95. void editLabel(QListWidgetItem *anItem);
  96. void saveAllInfo();
  97. void saveSegmentedPicture();
  98. void saveLegend();
  99. void loadInfo();
  100. void loadLegendFromFile();
  101. void setBoundingBoxTool(bool aButtonPressed);
  102. void setPolygonTool(bool aButtonPressed);
  103. void generateColors();
  104. void confirmSelection();
  105. void clearAll();
  106. void clearAllTool();
  107. void clearLabelList();
  108. void areaListPopupMenu(const QPoint &aPos);
  109. void labelListPopupMenu(const QPoint &aPos);
  110. void setDescription(QString aDescription);
  111. void onImageScaled();
  112. void onOptionsSet();
  113. void onSelectionStarted();
  114. void onAreaChange(QListWidgetItem *);
  115. void setPureData();
  116. void setLabelColor();
  117. void setLabelColor(int anID, QColor aColor);
  118. private:
  119. /* menu */
  120. QMenuBar *menu_bar_;
  121. QMenu *menu_file_;
  122. QMenu *menu_edit_;
  123. QMenu *menu_help_;
  124. QAction *action_open_images_;
  125. QAction *action_open_image_;
  126. QAction *action_open_labeled_image_;
  127. QAction *action_load_legend_;
  128. QAction *action_save_labels_;
  129. QAction *action_save_segmented_;
  130. QAction *action_save_legend_;
  131. QAction *action_quit_;
  132. QAction *action_undo_;
  133. QAction *action_redo_;
  134. QAction *action_bound_box_tool_;
  135. QAction *action_polygon_tool_;
  136. QAction *action_tagging_tool_;
  137. QAction *action_add_description_;
  138. QAction *action_options_;
  139. QAction *action_about_;
  140. QAction *action_help_content_;
  141. /* popup menu */
  142. QMenu *popup_area_list_;
  143. QAction *action_delete_area_;
  144. QAction *action_edit_area_;
  145. QMenu *popup_label_list_;
  146. QAction *action_toggle_priority_;
  147. QAction *action_set_color_;
  148. QAction *action_delete_label_;
  149. /* layouts */
  150. QHBoxLayout *layout_main_;
  151. QVBoxLayout *layout_left_;
  152. QVBoxLayout *layout_toolbox_;
  153. QVBoxLayout *layout_center_;
  154. QVBoxLayout *layout_frame_image_;
  155. QGridLayout *layout_image_widget_;
  156. QHBoxLayout *layout_center_buttons_;
  157. QVBoxLayout *layout_right_;
  158. QVBoxLayout *layout_labelbox_;
  159. QHBoxLayout *layout_labelbox_buttons_;
  160. /* widgets */
  161. QWidget *central_widget_;
  162. QFrame *frame_image_;
  163. QFrame *frame_center_;
  164. QFrame *frame_toolbox_;
  165. QFrame *frame_labelbox_;
  166. QPixmap *image_;
  167. ImageHolder *image_holder_;
  168. QLabel *label_toolbox_;
  169. QLabel *label_list_areas_;
  170. QListWidget *list_label_;
  171. QListWidget *list_areas_;
  172. ImageDescriptionForm image_description_form_;
  173. OptionsForm options_form_;
  174. QPushButton *button_bound_box_tool_;
  175. QPushButton *button_polygon_tool_;
  176. QPushButton *button_tagging_tool_;
  177. QPushButton *button_clear_selection_tool_;
  178. QPushButton *button_delete_all_labels_;
  179. QPushButton *button_generate_colors_;
  180. QPushButton *button_add_label_;
  181. QPushButton *button_remove_label_;
  182. QPushButton *button_prev_image_;
  183. QPushButton *button_next_image_;
  184. QPushButton *button_confirm_selection_;
  185. QButtonGroup *group_tools_;
  186. /* variables */
  187. int main_label_;
  188. int **pure_data_;
  189. int label_ID_;
  190. QString image_description_;
  191. QStringList *list_images_;
  192. QStringList::iterator current_image_;
  193. QList< BoundingBox > list_bounding_box_;
  194. QList< Polygon > list_polygon_;
  195. QList< uint > list_label_colors_;
  196. QString old_area_string_;
  197. /* options */
  198. bool auto_color_generation_;
  199. };
  200. #endif /* __IMAGELABELER_H__ */
  201. /*
  202. *
  203. */