123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- /*
- * ImageLabeler.h
- *
- * Created on: Oct 4, 2011
- * Author: Gapchich Vladislav
- */
- #ifndef __IMAGELABELER_H__
- #define __IMAGELABELER_H__
- #include "ImageHolder.h"
- #include "LineEditForm.h"
- #include "OptionsForm.h"
- #include <QMainWindow>
- #include <QDir>
- /* forward declarations */
- class QMenuBar;
- class QMenu;
- class QAction;
- class QHBoxLayout;
- class QVBoxLayout;
- class QGridLayout;
- class QPushButton;
- class QPixmap;
- class QLabel;
- class QScrollArea;
- class QFrame;
- class QListWidget;
- class QListWidgetItem;
- class QButtonGroup;
- class QDomDocument;
- class QDomElement;
- class QSettings;
- struct Image {
- QString image_;
- bool labeled_;
- bool pas_;
- };
- class ImageLabeler : public QMainWindow
- {
- Q_OBJECT
- protected:
- /* events */
- void resizeEvent(QResizeEvent *anEvent);
- void mousePressEvent(QMouseEvent *anEvent);
- void wheelEvent(QWheelEvent *anEvent);
- void keyPressEvent(QKeyEvent *anEvent);
- void keyReleaseEvent(QKeyEvent *anEvent);
- void closeEvent(QCloseEvent *anEvent);
- bool readSettings(QSettings *aSettings);
- bool writeSettings(QSettings *aSettings);
- void getImagesFromDir(const QDir &dir);
- void showWarning(const QString text);
- bool askForUnsavedData();
- void loadLegendFromNode(QDomElement *anElement);
- void addPoly(Polygon *poly);
- void addBBox(BoundingBox *bbox);
- void addPolyFromData(
- QString *aPolyData,
- int *labelID
- );
- void addBBoxFromData(
- QString *aBBoxData,
- int *labelID
- );
- Polygon polyFromData(
- QString *aPolyData
- );
- Polygon polyFromString(
- QString *aString,
- int *oldID
- );
- BoundingBox BBoxFromData(
- QString *aBBoxData
- );
- BoundingBox BBoxFromString(
- QString *aString,
- int *oldID
- );
- void enableTools();
- void disableTools();
- void legendToXml(QDomDocument *aDoc, QDomElement *aRoot);
- void objectsToXml(QDomDocument *aDoc, QDomElement *aRoot);
- void addImage(Image *anImage);
- bool loadInfo(QString filename);
- bool loadPascalFile(QString aFilename, QString aPath = QString());
- bool loadPascalPolys(QString aFilename);
- bool selectImage(int anImageID);
- public:
- ImageLabeler(QWidget *aParent = 0, QString aSettingsPath = QString());
- virtual ~ImageLabeler();
- public slots:
- void addLabel();
- void addLabel(
- int aLabelID,
- bool isMain,
- QString aLabel
- );
- void removeLabel();
- void setLabelID(QListWidgetItem *anItem);
- void addBBoxArea(
- int anID,
- BoundingBox aBBox,
- int itemID = -1
- );
- void addPolyArea(
- int aPolyID,
- Polygon aPoly,
- int itemID = -1
- );
- void deleteArea();
- void editArea();
- void toggleLabelPriority();
- void nextImage();
- void prevImage();
- void editLabel(QListWidgetItem *anItem);
- void saveAllInfo();
- void saveSegmentedPicture();
- void saveLegend();
- void loadImage();
- void loadImages();
- void loadInfo();
- void loadPascalFile();
- void loadPascalPolys();
- void loadLegendFromFile();
- void setBoundingBoxTool(bool aButtonPressed);
- void setPolygonTool(bool aButtonPressed);
- void generateColors();
- void confirmSelection();
- void clearAll();
- void clearAllTool();
- void clearLabelList();
- void clearLabelColorList();
- void areaListPopupMenu(const QPoint &aPos);
- void labelListPopupMenu(const QPoint &aPos);
- void setDataFromForm(QString aData);
- void onImageScaled();
- void onOptionsSet();
- void onSelectionStarted();
- void onAreaItemChange(QListWidgetItem *);
- void onAreaEdit();
- void setPureData();
- void setLabelColor();
- void setLabelColor(int anID, QColor aColor);
- void viewNormal();
- void viewSegmented();
- void interruptSearch();
- void selectImage(QListWidgetItem *);
- void removeImage();
- void imageListPopupMenu(const QPoint &);
- void writeSettings();
- private:
- /* menu */
- QMenuBar *menu_bar_;
- QMenu *menu_file_;
- QMenu *menu_pascal_;
- QMenu *menu_view_;
- QMenu *menu_edit_;
- QMenu *menu_help_;
- /* menu file */
- QAction *action_open_images_;
- QAction *action_open_image_;
- QAction *action_open_labeled_image_;
- QAction *action_load_legend_;
- QAction *action_save_labels_;
- QAction *action_save_segmented_;
- QAction *action_save_legend_;
- QAction *action_quit_;
- /* menu pascal */
- QAction *action_load_pascal_file_;
- QAction *action_load_pascal_poly_;
- /* menu view */
- QAction *action_view_normal_;
- QAction *action_view_segmented_;
- /* menu edit */
- QAction *action_undo_;
- QAction *action_redo_;
- QAction *action_bound_box_tool_;
- QAction *action_polygon_tool_;
- QAction *action_tagging_tool_;
- QAction *action_add_description_;
- QAction *action_options_;
- QAction *action_about_;
- QAction *action_help_content_;
- /* popup menu */
- QMenu *popup_area_list_;
- QAction *action_delete_area_;
- QAction *action_edit_area_;
- QMenu *popup_label_list_;
- QAction *action_toggle_priority_;
- QAction *action_set_color_;
- QAction *action_delete_label_;
- QMenu *popup_images_list_;
- QAction *action_remove_image_;
- /* layouts */
- QHBoxLayout *layout_main_;
- QVBoxLayout *layout_left_;
- QVBoxLayout *layout_toolbox_;
- QVBoxLayout *layout_center_;
- QVBoxLayout *layout_frame_image_;
- QGridLayout *layout_image_widget_;
- QHBoxLayout *layout_center_buttons_;
- QVBoxLayout *layout_right_;
- QVBoxLayout *layout_labelbox_;
- QHBoxLayout *layout_labelbox_buttons_;
- /* widgets */
- QWidget *central_widget_;
- //QFrame *frame_image_;
- QScrollArea *frame_image_;
- QFrame *frame_center_;
- QFrame *frame_toolbox_;
- QFrame *frame_labelbox_;
- QPixmap *image_;
- ImageHolder *image_holder_;
- QLabel *label_toolbox_;
- QLabel *label_list_areas_;
- QLabel *label_list_images_;
- QListWidget *list_label_;
- QListWidget *list_areas_;
- QListWidget *list_images_widget_;
- LineEditForm line_edit_form_;
- OptionsForm options_form_;
- QPushButton *button_bound_box_tool_;
- QPushButton *button_polygon_tool_;
- QPushButton *button_tagging_tool_;
- QPushButton *button_clear_selection_tool_;
- QPushButton *button_delete_all_labels_;
- QPushButton *button_generate_colors_;
- QPushButton *button_add_label_;
- QPushButton *button_remove_label_;
- QPushButton *button_prev_image_;
- QPushButton *button_next_image_;
- QPushButton *button_confirm_selection_;
- QButtonGroup *group_tools_;
- /* variables */
- Qt::KeyboardModifiers keyboard_modifier_;
- int main_label_;
- int **pure_data_;
- int label_ID_;
- int image_ID_;
- QString image_description_;
- QString tags_;
- QString PASCALpath_;
- QList< Image > *list_images_;
- //QStringList::iterator current_image_;
- QString current_image_;
- QString segmented_image_;
- QList< BoundingBox * > list_bounding_box_;
- QList< Polygon * > list_polygon_;
- QList< uint > list_label_colors_;
- QString old_area_string_;
- /* options */
- bool auto_color_generation_;
- /* flags */
- bool interrupt_search_;
- bool unsaved_data_;
- QSettings *settings_;
- };
- #endif /* __IMAGELABELER_H__ */
- /*
- *
- */
|