ImageLabeler.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. void addImage(QString *anImage);
  71. public:
  72. ImageLabeler(QWidget *aParent = 0);
  73. virtual ~ImageLabeler();
  74. public slots:
  75. void addLabel();
  76. void addLabel(
  77. int aLabelID,
  78. bool isMain,
  79. QString aLabel
  80. );
  81. void removeLabel();
  82. void setLabelID(QListWidgetItem *anItem);
  83. void addBBoxArea(
  84. int anID,
  85. BoundingBox aBBox,
  86. int itemID = -1
  87. );
  88. void addPolyArea(
  89. int aPolyID,
  90. Polygon aPoly,
  91. int itemID = -1
  92. );
  93. void deleteArea();
  94. void editArea();
  95. void toggleLabelPriority();
  96. void nextImage();
  97. void prevImage();
  98. void editLabel(QListWidgetItem *anItem);
  99. void saveAllInfo();
  100. void saveSegmentedPicture();
  101. void saveLegend();
  102. void loadImage();
  103. void loadImages();
  104. void loadInfo();
  105. void loadLegendFromFile();
  106. void setBoundingBoxTool(bool aButtonPressed);
  107. void setPolygonTool(bool aButtonPressed);
  108. void generateColors();
  109. void confirmSelection();
  110. void clearAll();
  111. void clearAllTool();
  112. void clearLabelList();
  113. void areaListPopupMenu(const QPoint &aPos);
  114. void labelListPopupMenu(const QPoint &aPos);
  115. void setDescription(QString aDescription);
  116. void onImageScaled();
  117. void onOptionsSet();
  118. void onSelectionStarted();
  119. void onAreaItemChange(QListWidgetItem *);
  120. void onAreaEdit();
  121. void setPureData();
  122. void setLabelColor();
  123. void setLabelColor(int anID, QColor aColor);
  124. void viewNormal();
  125. void viewSegmented();
  126. void interruptSearch();
  127. void selectImage(QListWidgetItem *);
  128. private:
  129. /* menu */
  130. QMenuBar *menu_bar_;
  131. QMenu *menu_file_;
  132. QMenu *menu_view_;
  133. QMenu *menu_edit_;
  134. QMenu *menu_help_;
  135. /* menu file */
  136. QAction *action_open_images_;
  137. QAction *action_open_image_;
  138. QAction *action_open_labeled_image_;
  139. QAction *action_load_legend_;
  140. QAction *action_save_labels_;
  141. QAction *action_save_segmented_;
  142. QAction *action_save_legend_;
  143. QAction *action_quit_;
  144. /* menu view */
  145. QAction *action_view_normal_;
  146. QAction *action_view_segmented_;
  147. /* menu edit */
  148. QAction *action_undo_;
  149. QAction *action_redo_;
  150. QAction *action_bound_box_tool_;
  151. QAction *action_polygon_tool_;
  152. QAction *action_tagging_tool_;
  153. QAction *action_add_description_;
  154. QAction *action_options_;
  155. QAction *action_about_;
  156. QAction *action_help_content_;
  157. /* popup menu */
  158. QMenu *popup_area_list_;
  159. QAction *action_delete_area_;
  160. QAction *action_edit_area_;
  161. QMenu *popup_label_list_;
  162. QAction *action_toggle_priority_;
  163. QAction *action_set_color_;
  164. QAction *action_delete_label_;
  165. /* layouts */
  166. QHBoxLayout *layout_main_;
  167. QVBoxLayout *layout_left_;
  168. QVBoxLayout *layout_toolbox_;
  169. QVBoxLayout *layout_center_;
  170. QVBoxLayout *layout_frame_image_;
  171. QGridLayout *layout_image_widget_;
  172. QHBoxLayout *layout_center_buttons_;
  173. QVBoxLayout *layout_right_;
  174. QVBoxLayout *layout_labelbox_;
  175. QHBoxLayout *layout_labelbox_buttons_;
  176. /* widgets */
  177. QWidget *central_widget_;
  178. //QFrame *frame_image_;
  179. QScrollArea *frame_image_;
  180. QFrame *frame_center_;
  181. QFrame *frame_toolbox_;
  182. QFrame *frame_labelbox_;
  183. QPixmap *image_;
  184. ImageHolder *image_holder_;
  185. QLabel *label_toolbox_;
  186. QLabel *label_list_areas_;
  187. QLabel *label_list_images_;
  188. QListWidget *list_label_;
  189. QListWidget *list_areas_;
  190. QListWidget *list_images_widget_;
  191. ImageDescriptionForm image_description_form_;
  192. OptionsForm options_form_;
  193. QPushButton *button_bound_box_tool_;
  194. QPushButton *button_polygon_tool_;
  195. QPushButton *button_tagging_tool_;
  196. QPushButton *button_clear_selection_tool_;
  197. QPushButton *button_delete_all_labels_;
  198. QPushButton *button_generate_colors_;
  199. QPushButton *button_add_label_;
  200. QPushButton *button_remove_label_;
  201. QPushButton *button_prev_image_;
  202. QPushButton *button_next_image_;
  203. QPushButton *button_confirm_selection_;
  204. QButtonGroup *group_tools_;
  205. /* variables */
  206. Qt::KeyboardModifiers keyboard_modifier_;
  207. int main_label_;
  208. int **pure_data_;
  209. int label_ID_;
  210. int image_ID_;
  211. QString image_description_;
  212. QStringList *list_images_;
  213. //QStringList::iterator current_image_;
  214. QString current_image_;
  215. QString segmented_image_;
  216. QList< BoundingBox * > list_bounding_box_;
  217. QList< Polygon * > list_polygon_;
  218. QList< uint > list_label_colors_;
  219. QString old_area_string_;
  220. /* options */
  221. bool auto_color_generation_;
  222. /* flags */
  223. bool interrupt_search_;
  224. bool unsaved_data_;
  225. };
  226. #endif /* __IMAGELABELER_H__ */
  227. /*
  228. *
  229. */