ObjWidget.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2011-2014, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7  * Redistributions of source code must retain the above copyright
8  notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright
10  notice, this list of conditions and the following disclaimer in the
11  documentation and/or other materials provided with the distribution.
12  * Neither the name of the Universite de Sherbrooke nor the
13  names of its contributors may be used to endorse or promote products
14  derived from this software without specific prior written permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
28 #ifndef OBJWIDGET_H_
29 #define OBJWIDGET_H_
30 
31 #include "find_object/FindObjectExp.h" // DLL export/import defines
32 
33 #include <opencv2/features2d/features2d.hpp>
34 #include <QWidget>
35 #include <QtCore/QMultiMap>
36 
37 class QAction;
38 class QMenu;
39 class QGraphicsView;
40 class QGraphicsScene;
41 class QGraphicsRectItem;
42 class QGraphicsItem;
43 class QLabel;
44 
45 namespace find_object {
46 
47 class KeypointItem;
48 class ImageKptsView;
49 
50 class FINDOBJECT_EXP ObjWidget : public QWidget
51 {
52  Q_OBJECT
53 
54 public:
55  ObjWidget(QWidget * parent = 0);
56  ObjWidget(int id, const std::vector<cv::KeyPoint> & keypoints, const QMultiMap<int,int> & words, const QImage & image, QWidget * parent = 0);
57  virtual ~ObjWidget();
58 
59  void setId(int id);
60  void updateImage(const QImage & image);
61  void updateData(const std::vector<cv::KeyPoint> & keypoints, const QMultiMap<int, int> & words=QMultiMap<int, int>());
62  void updateWords(const QMultiMap<int,int> & words);
63  void setTextLabel(const QString & text);
64  void resetKptsColor();
65  void resetKptsWordID();
66  void setKptColor(int index, const QColor & color);
67  void setKptWordID(int index, int wordId);
68  void setGraphicsViewMode(bool on);
69  void setAutoScale(bool autoScale);
70  void setSizedFeatures(bool on);
71  void setMirrorView(bool on);
72  void setAlpha(int alpha);
73  void setDeletable(bool deletable);
74  void setImageShown(bool shown);
75  void setFeaturesShown(bool shown);
76  void addRect(QGraphicsRectItem * rect);
77  void clearRoiSelection() {mousePressedPos_ = mouseCurrentPos_ = QPoint();update();}
78 
79  int id() const {return id_;}
80  const QColor & color() const {return color_;}
81  const std::vector<cv::KeyPoint> keypoints() const {return keypoints_;}
82  const QMap<int,int> & words() const {return words_;}
83  const QPixmap & pixmap() const {return pixmap_;}
84  QColor defaultColor(int id) const;
85  bool isImageShown() const;
86  bool isFeaturesShown() const;
87  bool isSizedFeatures() const;
88  bool isMirrorView() const;
89  //QGraphicsScene * scene() const;
90  std::vector<cv::KeyPoint> selectedKeypoints() const;
91  QList<QGraphicsItem*> selectedItems() const;
92 
93  QPixmap getSceneAsPixmap();
94 
95 protected:
96  virtual void paintEvent(QPaintEvent *event);
97  virtual void contextMenuEvent(QContextMenuEvent * event);
98  virtual void resizeEvent(QResizeEvent* event);
99  virtual void mousePressEvent(QMouseEvent * event);
100  virtual void mouseMoveEvent(QMouseEvent * event);
101  virtual void mouseReleaseEvent(QMouseEvent * event);
102 
103 Q_SIGNALS:
104  void removalTriggered(find_object::ObjWidget *);
105  void selectionChanged();
106  void roiChanged(const cv::Rect &);
107 
108 private:
109  void setupGraphicsView();
110  void drawKeypoints(QPainter * painter = 0);
111  void setupUi();
112  void updateItemsShown();
113  void computeScaleOffsets(float & scale, float & offsetX, float & offsetY);
114 
115 private:
116  int id_;
117  std::vector<cv::KeyPoint> keypoints_;
118  QMap<int,int> words_; //<keypoint, word>
119  QPixmap pixmap_;
120  QRect rect_;
121  QList<KeypointItem*> keypointItems_;
122  QGraphicsView * graphicsView_;
123  QVector<QColor> kptColors_;
124  QList<QGraphicsRectItem*> rectItems_;
126  int alpha_;
127  QLabel * label_;
128  QColor color_;
129 
130  // menu stuff
131  QString savedFileName_;
132  QMenu * menu_;
133  QAction * showImage_;
134  QAction * showFeatures_;
135  QAction * saveImage_;
136  QAction * mirrorView_;
137  QAction * delete_;
138  QAction * graphicsViewMode_;
139  QAction * autoScale_;
140  QAction * sizedFeatures_;
141  QAction * setAlpha_;
142  QAction * setColor_;
143 
144  // selection stuff
147 };
148 
149 } // namespace find_object
150 
151 #endif /* OBJWIDGET_H_ */
QVector< QColor > kptColors_
Definition: ObjWidget.h:123
const QColor & color() const
Definition: ObjWidget.h:80
QAction * sizedFeatures_
Definition: ObjWidget.h:140
std::vector< cv::KeyPoint > keypoints_
Definition: ObjWidget.h:117
#define FINDOBJECT_EXP
Definition: FindObjectExp.h:38
const std::vector< cv::KeyPoint > keypoints() const
Definition: ObjWidget.h:81
QAction * showFeatures_
Definition: ObjWidget.h:134
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
QGraphicsView * graphicsView_
Definition: ObjWidget.h:122
QList< KeypointItem * > keypointItems_
Definition: ObjWidget.h:121
QAction * graphicsViewMode_
Definition: ObjWidget.h:138
int id() const
Definition: ObjWidget.h:79
const QMap< int, int > & words() const
Definition: ObjWidget.h:82
QMap< int, int > words_
Definition: ObjWidget.h:118
QList< QGraphicsRectItem * > rectItems_
Definition: ObjWidget.h:124
const QPixmap & pixmap() const
Definition: ObjWidget.h:83


find_object_2d
Author(s): Mathieu Labbe
autogenerated on Mon Jun 10 2019 13:21:31