ImageLabeler.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. void viewNormal();
  120. void viewSegmented();
  121. void interruptSearch();
  122. private:
  123. /* menu */
  124. QMenuBar *menu_bar_;
  125. QMenu *menu_file_;
  126. QMenu *menu_view_;
  127. QMenu *menu_edit_;
  128. QMenu *menu_help_;
  129. /* menu file */
  130. QAction *action_open_images_;
  131. QAction *action_open_image_;
  132. QAction *action_open_labeled_image_;
  133. QAction *action_load_legend_;
  134. QAction *action_save_labels_;
  135. QAction *action_save_segmented_;
  136. QAction *action_save_legend_;
  137. QAction *action_quit_;
  138. /* menu view */
  139. QAction *action_view_normal_;
  140. QAction *action_view_segmented_;
  141. /* menu edit */
  142. QAction *action_undo_;
  143. QAction *action_redo_;
  144. QAction *action_bound_box_tool_;
  145. QAction *action_polygon_tool_;
  146. QAction *action_tagging_tool_;
  147. QAction *action_add_description_;
  148. QAction *action_options_;
  149. QAction *action_about_;
  150. QAction *action_help_content_;
  151. /* popup menu */
  152. QMenu *popup_area_list_;
  153. QAction *action_delete_area_;
  154. QAction *action_edit_area_;
  155. QMenu *popup_label_list_;
  156. QAction *action_toggle_priority_;
  157. QAction *action_set_color_;
  158. QAction *action_delete_label_;
  159. /* layouts */
  160. QHBoxLayout *layout_main_;
  161. QVBoxLayout *layout_left_;
  162. QVBoxLayout *layout_toolbox_;
  163. QVBoxLayout *layout_center_;
  164. QVBoxLayout *layout_frame_image_;
  165. QGridLayout *layout_image_widget_;
  166. QHBoxLayout *layout_center_buttons_;
  167. QVBoxLayout *layout_right_;
  168. QVBoxLayout *layout_labelbox_;
  169. QHBoxLayout *layout_labelbox_buttons_;
  170. /* widgets */
  171. QWidget *central_widget_;
  172. //QFrame *frame_image_;
  173. QScrollArea *frame_image_;
  174. QFrame *frame_center_;
  175. QFrame *frame_toolbox_;
  176. QFrame *frame_labelbox_;
  177. QPixmap *image_;
  178. ImageHolder *image_holder_;
  179. QLabel *label_toolbox_;
  180. QLabel *label_list_areas_;
  181. QListWidget *list_label_;
  182. QListWidget *list_areas_;
  183. ImageDescriptionForm image_description_form_;
  184. OptionsForm options_form_;
  185. QPushButton *button_bound_box_tool_;
  186. QPushButton *button_polygon_tool_;
  187. QPushButton *button_tagging_tool_;
  188. QPushButton *button_clear_selection_tool_;
  189. QPushButton *button_delete_all_labels_;
  190. QPushButton *button_generate_colors_;
  191. QPushButton *button_add_label_;
  192. QPushButton *button_remove_label_;
  193. QPushButton *button_prev_image_;
  194. QPushButton *button_next_image_;
  195. QPushButton *button_confirm_selection_;
  196. QButtonGroup *group_tools_;
  197. /* variables */
  198. int main_label_;
  199. int **pure_data_;
  200. int label_ID_;
  201. QString image_description_;
  202. QStringList *list_images_;
  203. QStringList::iterator current_image_;
  204. QString segmented_image_;
  205. QList< BoundingBox > list_bounding_box_;
  206. QList< Polygon > list_polygon_;
  207. QList< uint > list_label_colors_;
  208. QString old_area_string_;
  209. /* options */
  210. bool auto_color_generation_;
  211. /* flags */
  212. bool interrupt_search_;
  213. };
  214. #endif /* __IMAGELABELER_H__ */
  215. /*
  216. *
  217. */