ImageLabeler.h 6.5 KB

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