00001 #ifndef _QDISPLAY_LABELER_H_
00002 #define _QDISPLAY_LABELER_H_
00003
00004 #include <QObject>
00005 #include <QApplication>
00006
00007
00008 #include "qdisplay/Viewer.hpp"
00009 #include "qdisplay/ImageView.hpp"
00010 #include "qdisplay/Shape.hpp"
00011 #include "kernel/threads.hpp"
00012
00013
00014 namespace jafar {
00015 namespace qdisplay {
00016
00017
00018
00019 enum LabelMode { lmBoundingBox = 0, lmSizeOri, lmBlobs, lmCOUNT };
00020 static const std::string LabelModeNames[lmCOUNT] = {"BoundingBox", "SizeOri", "Blobs" };
00021
00022 class LabelBoundingBox
00023 {
00024 public:
00025 enum Quality { qlGood=0, qlOk, qlBad };
00026 public:
00027 LabelBoundingBox(): rect(), quality(qlGood) {}
00028 cv::Rect_<double> rect;
00029 Quality quality;
00030 };
00031
00032
00033 class LabelSizeOri
00034 {
00035 public:
00036 double size;
00037 double ori;
00038 double center_x, center_y;
00039 };
00040
00041
00042 class LabelBlobs
00043 {
00044 public:
00045 std::vector<std::pair<double,double> > centers;
00046 };
00047
00048
00049 class LabeledImage
00050 {
00051 public:
00052 enum Status { stUninit=0, stManual, stInterpol, stNothing };
00053 public:
00054 LabeledImage(): status(stUninit) {}
00055 std::string name;
00056 Status status;
00057 LabelBoundingBox lbbox;
00058 LabelSizeOri lsori;
00059 LabelBlobs lblob;
00060 };
00061
00062
00063
00091 class Labeler: public QObject
00092 {
00093 Q_OBJECT
00094 private:
00095 qdisplay::Viewer *viewer;
00096 qdisplay::ImageView *view;
00097 image::Image img;
00098 std::vector<LabeledImage> images;
00099 int nimages;
00100 int pos, lastpos;
00101 double w,h;
00102 LabelBoundingBox::Quality qual;
00103 qdisplay::Shape *cursor;
00104 qdisplay::Shape *mark;
00105 LabelMode mode;
00106 unsigned state;
00107 private:
00108 void display();
00109 void displayRects();
00110 void interpol(int start, LabeledImage::Status statusFind1, LabeledImage::Status statusFill1,
00111 LabeledImage::Status statusFind2, LabeledImage::Status statusFill2);
00112 void interpol(int before, int after, LabeledImage::Status status);
00113 void save();
00114 void load();
00115 void increaseSize(double inc);
00116 void decreaseSize(double inc);
00117 void remove();
00118 void next();
00119 void prev();
00120 void find(LabeledImage::Status status);
00121 void quality(LabelBoundingBox::Quality quality);
00122 void switch_mode();
00123 public:
00124 Labeler(int nimages, char** images);
00125 ~Labeler();
00126 public slots:
00127 void onKeyPress(QKeyEvent *event);
00128 void onMouseClick(QGraphicsSceneMouseEvent *mouseEvent, bool isClick);
00129 void onMouseMove(QGraphicsSceneMouseEvent *mouseEvent);
00130 };
00131
00132
00133
00134 }}
00135
00136 namespace cv {
00137 template<typename T> Rect_<T> operator+(Rect_<T> const& A, Rect_<T> const& B)
00138 { return Rect(A.x+B.x, A.y+B.y, A.width+B.width, A.height+B.height); }
00139 template<typename T> Rect_<T> operator-(Rect_<T> const& A, Rect_<T> const& B)
00140 { return Rect(A.x-B.x, A.y-B.y, A.width-B.width, A.height-B.height); }
00141 template<typename T> Rect_<T> operator*(Rect_<T> const& A, T b)
00142 { return Rect(A.x*b, A.y*b, A.width*b, A.height*b); }
00143 template<typename T> Rect_<T> operator/(Rect_<T> const& A, T b)
00144 { return Rect(A.x/b, A.y/b, A.width/b, A.height/b); }
00145 }
00146
00147 #endif
00148