ImageLabeler.h 6.2 KB

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