ImageLabeler.h 5.0 KB

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