ImageLabeler.h 5.7 KB

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