2 #include "opencv/SIFT.h" 3 #include "LinearMapper.h" 13 int height = img.rows;
17 if (img.channels() != 1) cvtColor(img, I, cv::ColorConversionCodes::COLOR_RGB2GRAY);
20 Ptr<xfeatures2d::SIFT> sift = xfeatures2d::SIFT::create();
23 std::vector<KeyPoint> vKeyPoints;
25 for (y = 0; y < height; y++)
26 for (x = 0; x < width; x++)
27 vKeyPoints.push_back(KeyPoint(static_cast<float>(x), static_cast<float>(y), 1.0f));
32 sift->detectAndCompute(I, Mat(), vKeyPoints, descriptors,
true);
34 const int nFeatures = descriptors.cols;
35 DGM_ASSERT(nFeatures == 128);
36 DGM_ASSERT(nFeatures < CV_CN_MAX);
39 vec_mat_t vFeatures(nFeatures);
40 for (i = 0; i < nFeatures; i++) vFeatures[i].create(img.size(), CV_8UC1);
42 std::vector<byte *> pFeatures(nFeatures);
44 for (y = 0; y < height; y++) {
45 for (i = 0; i < nFeatures; i++) pFeatures[i] = vFeatures[i].ptr<byte>(y);
46 for (x = 0; x < width; x++) {
47 float *pDescriptors = descriptors.ptr<
float>(y * width + x);
48 for (i = 0; i < nFeatures; i++)
49 pFeatures[i][x] = linear_mapper<byte>(pDescriptors[i], 0.0f, 255.0f);
54 merge(vFeatures, res);
virtual Mat get(void) const
Extracts and returns the required feature.