ImageLabeler.h 6.6 KB

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