keypointdetector.cpp
1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <opencv2/features2d/features2d.hpp>
#include <openbr/plugins/openbr_internal.h>
#include <openbr/core/opencvutils.h>
using namespace cv;
namespace br
{
/*!
* \ingroup transforms
* \brief Wraps OpenCV Key Point Detector
* \author Josh Klontz \cite jklontz
*/
class KeyPointDetectorTransform : public UntrainableTransform
{
Q_OBJECT
Q_PROPERTY(QString detector READ get_detector WRITE set_detector RESET reset_detector STORED false)
BR_PROPERTY(QString, detector, "SIFT")
Ptr<FeatureDetector> featureDetector;
void init()
{
featureDetector = FeatureDetector::create(detector.toStdString());
if (featureDetector.empty())
qFatal("Failed to create KeyPointDetector: %s", qPrintable(detector));
}
void project(const Template &src, Template &dst) const
{
dst = src;
std::vector<KeyPoint> keyPoints;
try {
featureDetector->detect(src, keyPoints);
} catch (...) {
qWarning("Key point detection failed for file %s", qPrintable(src.file.name));
dst.file.fte = true;
}
QList<Rect> rects;
foreach (const KeyPoint &keyPoint, keyPoints)
rects.append(Rect(keyPoint.pt.x-keyPoint.size/2, keyPoint.pt.y-keyPoint.size/2, keyPoint.size, keyPoint.size));
dst.file.setRects(OpenCVUtils::fromRects(rects));
}
};
BR_REGISTER(Transform, KeyPointDetectorTransform)
} // namespace br
#include "metadata/keypointdetector.moc"