Stitching module with SIFT and DAISY algorithm
Hi, I tried to use SIFT and DAISY in Stitching module in Opencv 3.0. Below is the detailed code changes I have done. In sources\modules\stitcing\src\matchers.cpp, following codes were added
//***************************
SiftFeaturesFinder::SiftFeaturesFinder(
//double hess_thresh, int num_octaves, int num_layers,
//int num_octaves_descr, int num_layers_descr)
int nfeatures, int nOctaveLayers,
double contrastThreshold, double edgeThreshold,
double sigma)
{
#ifdef HAVE_OPENCV_XFEATURES2D
//sift = SIFT::create(nfeatures, nOctaveLayers, contrastThreshold, edgeThreshold, sigma);
Ptr<SIFT> sift = SIFT::create(nfeatures, nOctaveLayers, contrastThreshold, edgeThreshold, sigma);
//sift = SIFT::create();
if (!sift)
CV_Error(Error::StsNotImplemented, "OpenCV was built without SIFT support");
#endif
}
void SiftFeaturesFinder::find(InputArray image, ImageFeatures &features)
{
UMat gray_image;
CV_Assert((image.type() == CV_8UC3) || (image.type() == CV_8UC1));
if (image.type() == CV_8UC3)
{
cvtColor(image, gray_image, COLOR_BGR2GRAY);
}
else
{
gray_image = image.getUMat();
}
if (!sift)
{
detector_->detect(gray_image, features.keypoints);
extractor_->compute(gray_image, features.keypoints, features.descriptors);
}
else
{
UMat descriptors;
sift->detectAndCompute(gray_image, Mat(), features.keypoints, descriptors);
features.descriptors = descriptors.reshape(1, (int)features.keypoints.size());
}
}
//**************
//***************************
DAISYFeaturesFinder::DAISYFeaturesFinder(
//double hess_thresh, int num_octaves, int num_layers,
//int num_octaves_descr, int num_layers_descr)
float radius, int q_radius, int q_theta,
int q_hist, int norm, InputArray H,
bool interpolation, bool use_orientation)
{
#ifdef HAVE_OPENCV_XFEATURES2D
//sift = SIFT::create(nfeatures, nOctaveLayers, contrastThreshold, edgeThreshold, sigma);
Ptr<DAISY> daisy = DAISY::create();
//sift = SIFT::create();
if (!daisy)
CV_Error(Error::StsNotImplemented, "OpenCV was built without daisy support");
#endif
}
void DAISYFeaturesFinder::find(InputArray image, ImageFeatures &features)
{
UMat gray_image;
CV_Assert((image.type() == CV_8UC3) || (image.type() == CV_8UC1));
if (image.type() == CV_8UC3)
{
cvtColor(image, gray_image, COLOR_BGR2GRAY);
}
else
{
gray_image = image.getUMat();
}
if (!daisy)
{
detector_->detect(gray_image, features.keypoints);
extractor_->compute(gray_image, features.keypoints, features.descriptors);
}
else
{
UMat descriptors;
daisy->detectAndCompute(gray_image, Mat(), features.keypoints, descriptors);
features.descriptors = descriptors.reshape(1, (int)features.keypoints.size());
}
}
//***************
also, the matchers.hpp was revised. Besides, I changed the opencv3/sources/samples/cpp/stitching_detailed.cpp and to enable SIFT and DAISY by adding the following codes:
else if (features_type == "sift")
{
finder = makePtr<SiftFeaturesFinder>();
}
else if (features_type == "daisy")
{
finder = makePtr<DAISYFeaturesFinder>();
}
else
{
cout << "Unknown 2D features type: '" << features_type << "'.\n";
return -1;
}
The final codes can be built and linked well, but the program would stop when executed the finder algorithm (SIFT or DAISY). I do not know what is wrong in the codes. I used to use this codes in Opencv 2.0, and it works well.
"but it would be broken when executed the finder algorithm " - that's a bit unclear. can you try to be more exact ? are there errors ? what is the problem ?