ObjWidget.h
Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2011-2014, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions are met:
00007     * Redistributions of source code must retain the above copyright
00008       notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright
00010       notice, this list of conditions and the following disclaimer in the
00011       documentation and/or other materials provided with the distribution.
00012     * Neither the name of the Universite de Sherbrooke nor the
00013       names of its contributors may be used to endorse or promote products
00014       derived from this software without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00017 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
00020 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00021 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00022 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00023 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00025 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 */
00027 
00028 #ifndef OBJWIDGET_H_
00029 #define OBJWIDGET_H_
00030 
00031 #include "find_object/FindObjectExp.h" // DLL export/import defines
00032 
00033 #include <opencv2/features2d/features2d.hpp>
00034 #include <QtGui/QWidget>
00035 #include <QtCore/QMultiMap>
00036 
00037 class QAction;
00038 class QMenu;
00039 class QGraphicsView;
00040 class QGraphicsScene;
00041 class QGraphicsRectItem;
00042 class QGraphicsItem;
00043 class QLabel;
00044 
00045 namespace find_object {
00046 
00047 class KeypointItem;
00048 class ImageKptsView;
00049 
00050 class FINDOBJECT_EXP ObjWidget : public QWidget
00051 {
00052         Q_OBJECT
00053 
00054 public:
00055         ObjWidget(QWidget * parent = 0);
00056         ObjWidget(int id, const std::vector<cv::KeyPoint> & keypoints, const QImage & image, QWidget * parent = 0);
00057         virtual ~ObjWidget();
00058 
00059         void setId(int id);
00060         void setData(const std::vector<cv::KeyPoint> & keypoints, const QImage & image);
00061         void setTextLabel(const QString & text);
00062         void resetKptsColor();
00063         void setKptColor(int index, const QColor & color);
00064         void setGraphicsViewMode(bool on);
00065         void setAutoScale(bool autoScale);
00066         void setSizedFeatures(bool on);
00067         void setMirrorView(bool on);
00068         void setAlpha(int alpha);
00069         void setDeletable(bool deletable);
00070         void setImageShown(bool shown);
00071         void setFeaturesShown(bool shown);
00072         void addRect(QGraphicsRectItem * rect);
00073         void clearRoiSelection() {mousePressedPos_ = mouseCurrentPos_ = QPoint();update();}
00074 
00075         int id() const {return id_;}
00076         const QColor & color() const {return color_;}
00077         const std::vector<cv::KeyPoint> keypoints() const {return keypoints_;}
00078         const QPixmap & pixmap() const {return pixmap_;}
00079         QColor defaultColor() const;
00080         bool isImageShown() const;
00081         bool isFeaturesShown() const;
00082         bool isSizedFeatures() const;
00083         bool isMirrorView() const;
00084         //QGraphicsScene * scene() const;
00085         std::vector<cv::KeyPoint> selectedKeypoints() const;
00086         QList<QGraphicsItem*> selectedItems() const;
00087 
00088         QPixmap getSceneAsPixmap();
00089 
00090 protected:
00091         virtual void paintEvent(QPaintEvent *event);
00092         virtual void contextMenuEvent(QContextMenuEvent * event);
00093         virtual void resizeEvent(QResizeEvent* event);
00094         virtual void mousePressEvent(QMouseEvent * event);
00095         virtual void mouseMoveEvent(QMouseEvent * event);
00096         virtual void mouseReleaseEvent(QMouseEvent * event);
00097 
00098 Q_SIGNALS:
00099         void removalTriggered(find_object::ObjWidget *);
00100         void selectionChanged();
00101         void roiChanged(const cv::Rect &);
00102 
00103 private:
00104         void setupGraphicsView();
00105         void drawKeypoints(QPainter * painter = 0);
00106         void setupUi();
00107         void updateItemsShown();
00108         void computeScaleOffsets(float & scale, float & offsetX, float & offsetY);
00109 
00110 private:
00111         int id_;
00112         std::vector<cv::KeyPoint> keypoints_;
00113         QPixmap pixmap_;
00114         QList<KeypointItem*> keypointItems_;
00115         QGraphicsView * graphicsView_;
00116         QVector<QColor> kptColors_;
00117         QList<QGraphicsRectItem*> rectItems_;
00118         bool graphicsViewInitialized_;
00119         int alpha_;
00120         QLabel * label_;
00121         QColor color_;
00122 
00123         // menu stuff
00124         QString savedFileName_;
00125         QMenu * menu_;
00126         QAction * showImage_;
00127         QAction * showFeatures_;
00128         QAction * saveImage_;
00129         QAction * mirrorView_;
00130         QAction * delete_;
00131         QAction * graphicsViewMode_;
00132         QAction * autoScale_;
00133         QAction * sizedFeatures_;
00134         QAction * setAlpha_;
00135         QAction * setColor_;
00136 
00137         // selection stuff
00138         QPoint mousePressedPos_;
00139         QPoint mouseCurrentPos_;
00140 };
00141 
00142 } // namespace find_object
00143 
00144 #endif /* OBJWIDGET_H_ */


find_object_2d
Author(s): Mathieu Labbe
autogenerated on Thu Aug 27 2015 13:00:33