VAT  3.0
Video Analysis Tool
LBSP.h
1 #pragma once
2 
3 #include <opencv2/core/core.hpp>
4 #include <opencv2/imgproc/imgproc.hpp>
5 #include <opencv2/features2d/features2d.hpp>
6 #include "DistanceUtils.h"
7 
19 class LBSP : public cv::Feature2D {
20 public:
22  LBSP(size_t nThreshold);
24  LBSP(float fRelThreshold, size_t nThresholdOffset=0);
26  virtual ~LBSP();
28  virtual void read(const cv::FileNode&);
30  virtual void write(cv::FileStorage&) const;
32  virtual void setReference(const cv::Mat&);
34  virtual int descriptorSize() const;
36  virtual int descriptorType() const;
38  virtual bool isUsingRelThreshold() const;
40  virtual float getRelThreshold() const;
42  virtual size_t getAbsThreshold() const;
43 
45  void compute2(const cv::Mat& oImage, std::vector<cv::KeyPoint>& voKeypoints, cv::Mat& oDescriptors) const;
47  void compute2(const std::vector<cv::Mat>& voImageCollection, std::vector<std::vector<cv::KeyPoint> >& vvoPointCollection, std::vector<cv::Mat>& voDescCollection) const;
48 
50  inline static void computeGrayscaleDescriptor(const cv::Mat& oInputImg, const uchar _ref, const int _x, const int _y, const size_t _t, ushort& _res) {
51  CV_DbgAssert(!oInputImg.empty());
52  CV_DbgAssert(oInputImg.type()==CV_8UC1);
53  CV_DbgAssert(LBSP::DESC_SIZE==2); // @@@ also relies on a constant desc size
54  CV_DbgAssert(_x>=(int)LBSP::PATCH_SIZE/2 && _y>=(int)LBSP::PATCH_SIZE/2);
55  CV_DbgAssert(_x<oInputImg.cols-(int)LBSP::PATCH_SIZE/2 && _y<oInputImg.rows-(int)LBSP::PATCH_SIZE/2);
56  const size_t _step_row = oInputImg.step.p[0];
57  const uchar* const _data = oInputImg.data;
58  #include "LBSP_16bits_dbcross_1ch.i"
59  }
60 
62  inline static void computeRGBDescriptor(const cv::Mat& oInputImg, const uchar* const _ref, const int _x, const int _y, const size_t* const _t, ushort* _res) {
63  CV_DbgAssert(!oInputImg.empty());
64  CV_DbgAssert(oInputImg.type()==CV_8UC3);
65  CV_DbgAssert(LBSP::DESC_SIZE==2); // @@@ also relies on a constant desc size
66  CV_DbgAssert(_x>=(int)LBSP::PATCH_SIZE/2 && _y>=(int)LBSP::PATCH_SIZE/2);
67  CV_DbgAssert(_x<oInputImg.cols-(int)LBSP::PATCH_SIZE/2 && _y<oInputImg.rows-(int)LBSP::PATCH_SIZE/2);
68  const size_t _step_row = oInputImg.step.p[0];
69  const uchar* const _data = oInputImg.data;
70  #include "LBSP_16bits_dbcross_3ch3t.i"
71  }
72 
74  inline static void computeRGBDescriptor(const cv::Mat& oInputImg, const uchar* const _ref, const int _x, const int _y, const size_t _t, ushort* _res) {
75  CV_DbgAssert(!oInputImg.empty());
76  CV_DbgAssert(oInputImg.type()==CV_8UC3);
77  CV_DbgAssert(LBSP::DESC_SIZE==2); // @@@ also relies on a constant desc size
78  CV_DbgAssert(_x>=(int)LBSP::PATCH_SIZE/2 && _y>=(int)LBSP::PATCH_SIZE/2);
79  CV_DbgAssert(_x<oInputImg.cols-(int)LBSP::PATCH_SIZE/2 && _y<oInputImg.rows-(int)LBSP::PATCH_SIZE/2);
80  const size_t _step_row = oInputImg.step.p[0];
81  const uchar* const _data = oInputImg.data;
82  #include "LBSP_16bits_dbcross_3ch1t.i"
83  }
84 
86  inline static void computeSingleRGBDescriptor(const cv::Mat& oInputImg, const uchar _ref, const int _x, const int _y, const size_t _c, const size_t _t, ushort& _res) {
87  CV_DbgAssert(!oInputImg.empty());
88  CV_DbgAssert(oInputImg.type()==CV_8UC3 && _c<3);
89  CV_DbgAssert(LBSP::DESC_SIZE==2); // @@@ also relies on a constant desc size
90  CV_DbgAssert(_x>=(int)LBSP::PATCH_SIZE/2 && _y>=(int)LBSP::PATCH_SIZE/2);
91  CV_DbgAssert(_x<oInputImg.cols-(int)LBSP::PATCH_SIZE/2 && _y<oInputImg.rows-(int)LBSP::PATCH_SIZE/2);
92  const size_t _step_row = oInputImg.step.p[0];
93  const uchar* const _data = oInputImg.data;
94  #include "LBSP_16bits_dbcross_s3ch.i"
95  }
96 
98  static void reshapeDesc(cv::Size oSize, const std::vector<cv::KeyPoint>& voKeypoints, const cv::Mat& oDescriptors, cv::Mat& oOutput);
100  static void calcDescImgDiff(const cv::Mat& oDesc1, const cv::Mat& oDesc2, cv::Mat& oOutput, bool bForceMergeChannels=false);
102  static void validateKeyPoints(std::vector<cv::KeyPoint>& voKeypoints, cv::Size oImgSize);
104  static void validateROI(cv::Mat& oROI);
106  static const size_t PATCH_SIZE = 5;
108  static const size_t DESC_SIZE = 2;
109 
110 protected:
112  virtual void computeImpl(const cv::Mat& oImage, std::vector<cv::KeyPoint>& voKeypoints, cv::Mat& oDescriptors) const;
113 
114  const bool m_bOnlyUsingAbsThreshold;
115  const float m_fRelThreshold;
116  const size_t m_nThreshold;
117  cv::Mat m_oRefImage;
118 };
virtual void write(cv::FileStorage &) const
writes extractor params to the specified file storage @@ not impl
Definition: LBSP.cpp:23
static void calcDescImgDiff(const cv::Mat &oDesc1, const cv::Mat &oDesc2, cv::Mat &oOutput, bool bForceMergeChannels=false)
utility function, used to illustrate the difference between two descriptor images ...
Definition: LBSP.cpp:262
static const size_t DESC_SIZE
utility, specifies the number of bytes per descriptor (should be the same as calling &#39;descriptorSize(...
Definition: LBSP.h:108
static void validateROI(cv::Mat &oROI)
utility function, used to filter out bad pixels in a ROI that would trigger out of bounds error becau...
Definition: LBSP.cpp:311
static void computeRGBDescriptor(const cv::Mat &oInputImg, const uchar *const _ref, const int _x, const int _y, const size_t *const _t, ushort *_res)
utility function, shortcut/lightweight/direct single-point LBSP computation function for extra flexib...
Definition: LBSP.h:62
virtual float getRelThreshold() const
returns the current relative threshold used for comparisons (-1 = invalid/not used) ...
Definition: LBSP.cpp:44
virtual void read(const cv::FileNode &)
loads extractor params from the specified file node @@ not impl
Definition: LBSP.cpp:19
Definition: LBSP.h:19
virtual size_t getAbsThreshold() const
returns the current absolute threshold used for comparisons (-1 = invalid/not used) ...
Definition: LBSP.cpp:48
virtual ~LBSP()
default destructor
Definition: LBSP.cpp:17
virtual void setReference(const cv::Mat &)
sets the &#39;reference&#39; image to be used for inter-frame comparisons (note: if no image is set or if the...
Definition: LBSP.cpp:27
virtual bool isUsingRelThreshold() const
returns whether this extractor is using a relative threshold or not
Definition: LBSP.cpp:40
LBSP(size_t nThreshold)
constructor 1, threshold = absolute intensity &#39;similarity&#39; threshold used when computing comparisons ...
Definition: LBSP.cpp:3
static void computeRGBDescriptor(const cv::Mat &oInputImg, const uchar *const _ref, const int _x, const int _y, const size_t _t, ushort *_res)
utility function, shortcut/lightweight/direct single-point LBSP computation function for extra flexib...
Definition: LBSP.h:74
static void validateKeyPoints(std::vector< cv::KeyPoint > &voKeypoints, cv::Size oImgSize)
utility function, used to filter out bad keypoints that would trigger out of bounds error because the...
Definition: LBSP.cpp:307
static void computeGrayscaleDescriptor(const cv::Mat &oInputImg, const uchar _ref, const int _x, const int _y, const size_t _t, ushort &_res)
utility function, shortcut/lightweight/direct single-point LBSP computation function for extra flexib...
Definition: LBSP.h:50
virtual int descriptorSize() const
returns the current descriptor size, in bytes
Definition: LBSP.cpp:32
static void reshapeDesc(cv::Size oSize, const std::vector< cv::KeyPoint > &voKeypoints, const cv::Mat &oDescriptors, cv::Mat &oOutput)
utility function, used to reshape a descriptors matrix to its input image size via their keypoint loc...
Definition: LBSP.cpp:235
static void computeSingleRGBDescriptor(const cv::Mat &oInputImg, const uchar _ref, const int _x, const int _y, const size_t _c, const size_t _t, ushort &_res)
utility function, shortcut/lightweight/direct single-point LBSP computation function for extra flexib...
Definition: LBSP.h:86
virtual void computeImpl(const cv::Mat &oImage, std::vector< cv::KeyPoint > &voKeypoints, cv::Mat &oDescriptors) const
classic &#39;compute&#39; implementation, based on the regular DescriptorExtractor::computeImpl arguments & e...
Definition: LBSP.cpp:221
virtual int descriptorType() const
returns the current descriptor data type
Definition: LBSP.cpp:36
void compute2(const cv::Mat &oImage, std::vector< cv::KeyPoint > &voKeypoints, cv::Mat &oDescriptors) const
similar to DescriptorExtractor::compute(const cv::Mat& image, ...), but in this case, the descriptors matrix has the same shape as the input matrix (possibly slower, but the result can be displayed)
Definition: LBSP.cpp:200
static const size_t PATCH_SIZE
utility, specifies the pixel size of the pattern used (width and height)
Definition: LBSP.h:106