Nainstaloval jsem si nějaké neoficiální knihovny do OpenCV a narazil jsem na menší zádrhel. Problém už někdo shrnul, takže dám link.
V souboru nonfree.hpp je toto:
#ifndef __OPENCV_XFEATURES2D_FEATURES_2D_HPP__
#define __OPENCV_XFEATURES2D_FEATURES_2D_HPP__
#include "opencv2/features2d.hpp"
namespace cv
{
namespace xfeatures2d
{
//! @addtogroup xfeatures2d_nonfree
//! @{
/** @brief Class for extracting keypoints and computing descriptors using the Scale Invariant Feature Transform
(SIFT) algorithm by D. Lowe @cite Lowe04 .
*/
class CV_EXPORTS_W SIFT : public Feature2D
{
public:
/**
@param nfeatures The number of best features to retain. The features are ranked by their scores
(measured in SIFT algorithm as the local contrast)
@param nOctaveLayers The number of layers in each octave. 3 is the value used in D. Lowe paper. The
number of octaves is computed automatically from the image resolution.
@param contrastThreshold The contrast threshold used to filter out weak features in semi-uniform
(low-contrast) regions. The larger the threshold, the less features are produced by the detector.
@param edgeThreshold The threshold used to filter out edge-like features. Note that the its meaning
is different from the contrastThreshold, i.e. the larger the edgeThreshold, the less features are
filtered out (more features are retained).
@param sigma The sigma of the Gaussian applied to the input image at the octave \#0. If your image
is captured with a weak camera with soft lenses, you might want to reduce the number.
*/
CV_WRAP static Ptr<SIFT> create( int nfeatures = 0, int nOctaveLayers = 3,
double contrastThreshold = 0.04, double edgeThreshold = 10,
double sigma = 1.6);
};
typedef SIFT SiftFeatureDetector;
typedef SIFT SiftDescriptorExtractor;}} // konec namespace
Rada na answers.opencv.org
yes, they are all 'abstract' (lack a public constructor).
the only way to make one is the 'create' function, like:
using namespace cv::xfeatures2d; Ptr<SIFT> sift = SIFT::create(...);
Nyní můj kód - implementace:
#include <stdio.h>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/xfeatures2d/nonfree.hpp"
#include "opencv2/nonfree/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace cv;
using namespace cv::xfeatures2d;
Ptr<SIFT> sift = SIFT::create(int v);
// ... main ...
int minHessian = 400;
SurfFeatureDetector detector( minHessian );
// zkráceno
to je soubor feature_detection.cpp
Na posledním řádku byla chyba, takže asi potřebuju definovat vlastní konstruktor.
Zkusil jsem do feature_detection.cpp přidat:
Ptr<SIFT> sift = SIFT::create(int v);
a dostal jsem hlášku:
error C2144: syntax error : 'int' should be preceded by ')'
Jak to vyřešit? Mám zkusit přidat do nonfree.hpp něco jako
CV_WRAP static Ptr<SURF> create(double hessianThreshold=100);
Taková funkce ale v knihovně asi není definována. Měl bych ji tedy pak definovat sám? Nevím co s tím a jak to rozjet.