How to add or modify SIFT 's funtion

In opencv 3.4.3 ,using SIFT I want provide gpyr and dogpyr to produce keypoints and descriptors ,I try to add a function or modify dectectAndCompute()(added gpyr and dogpyr) in files include sift.cpp,features2d.hpp,xfeatures2d.hpp,nonfree.hpp. Result is failed . error message undefine to reference .I would like someone to help me.

Welcome,

Can you give more details and a code snippet? We need more information to reproduce the error or understand what exactly the problem is.

in opencv 3.4.3 I modify features2d.hpp to add gpyr and dogpyr.
CV_WRAP void detectAndCompute( InputArray image, InputArray mask, std::vector& gpyr, std::vector& dogpyr, CV_OUT std::vector& keypoints, OutputArray descriptors,
bool useProvidedKeypoints=false ) ;
I modify two places in sift.cpp to add gpyr and dogpyr.

  1. void detectAndCompute(InputArray img, InputArray mask,
    std::vector& gpyr, std::vector& dogpyr,
    std::vector& keypoints, OutputArray descriptors,
    bool useProvidedKeypoints = false) ;
  2. void SIFT_Impl1::detectAndCompute(InputArray _image, InputArray _mask, std::vector& gpyr, std::vector& dogpyr,
    std::vector& keypoints,OutputArray _descriptors
    ,bool useProvidedKeypoints) I remark createInitialImage buildGaussianPyramid and buildDoGPyramid,I provide gpyr and dogpyr.
    I compile sift.cpp to liblibsift.a as follows:
    Building file: …/src/sift.cpp
    Invoking: ARM v8 Linux g++ compiler
    aarch64-linux-gnu-g++ -Wall -O2 -c -fmessage-length=0 -MT"src/sift.o" -static --sysroot=/home/lsding/opt/pkg/petalinux/2020.1/sysroots/aarch64-xilinx-linux -I/home/lsding/opt/pkg/petalinux/2020.1/sysroots/aarch64-xilinx-linux/usr/include -MMD -MP -MF"src/sift.d" -MT"src/sift.o" -o “src/sift.o” “…/src/sift.cpp”
    Finished building: …/src/sift.cpp

Building target: liblibsift.a
Invoking: ARM v8 Linux archiver
aarch64-linux-gnu-ar -r “liblibsift.a” ./src/sift.o
/home/lsding/opt/pkg/Vitis/2020.1/gnu/aarch64/lin/aarch64-linux/bin/…/x86_64-petalinux-linux/usr/bin/aarch64-xilinx-linux/aarch64-xilinx-linux-ar.real: creating liblibsift.a
Finished building target: liblibsift.a

I program test1.cpp as follows:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/xfeatures2d.hpp>
#include
#include
using namespace std;
using namespace cv;

int main(int argc, const char* argv[])
{
if (argc != 7) {
printf(“Usage: test1.elf im1 im2 nOctaveLayers sigma contrastThreshold disp\n”);
return -1;
}
int nOctaveLayers,disp;
double contrastThreshold,sigma ;
std::string::size_type sz;
nOctaveLayers=std::stoi(argv[3],nullptr,10);
sigma=std::stod(argv[4],&sz);
contrastThreshold=std::stod(argv[5],&sz);
disp=std::stoi(argv[6],nullptr,10);
const cv::Mat input1 = cv::imread(argv[1], 0);
const cv::Mat input2 = cv::imread(argv[2], 0);
cv::Ptrcv::xfeatures2d::SIFT sift= cv::xfeatures2d::SIFT::create(0,nOctaveLayers,contrastThreshold,10,sigma);

std::vectorcv::KeyPoint keypoints1,keypoints2;
std::vectorcv::Matgpyr,dogpyr;
Mat descriptors1, descriptors2,mask;
sift->detectAndCompute(input1, mask, gpyr,dogpyr,keypoints1, descriptors1,false);
sift->detectAndCompute(input2, mask,gpyr,dogpyr,keypoints2, descriptors2,false);
BFMatcher matcher;
std::vector< DMatch > matches;
Mat imMatches;
matcher.match( descriptors1, descriptors2, matches );
cv::drawMatches(input1, keypoints1, input2, keypoints2, matches, imMatches);
imwrite(“matches1.jpg”, imMatches);waitKey(15000);
if(disp>0)
{
cv::namedWindow(“match”,WINDOW_AUTOSIZE);
imshow(“match”,imMatches);waitKey(15000);
cv::destroyWindow(“match”);
}
return 0;
}

compile and link as follows:
Building file: …/src/test1.cpp
Invoking: ARM v8 Linux g++ compiler
aarch64-linux-gnu-g++ -DOPENCV_ENABLE_NONFREE=1 -Wall -O2 -c -fmessage-length=0 -MT"src/test1.o" --sysroot=/home/lsding/opt/pkg/petalinux/2020.1/sysroots/aarch64-xilinx-linux -I/home/lsding/opt/pkg/petalinux/2020.1/sysroots/aarch64-xilinx-linux/usr/include -MMD -MP -MF"src/test1.d" -MT"src/test1.o" -o “src/test1.o” “…/src/test1.cpp”
Finished building: …/src/test1.cpp

Building target: test1.elf
Invoking: ARM v8 Linux g++ linker
aarch64-linux-gnu-g++ -L"/home/lsding/worksp2/libsift/Release/src" -L/home/lsding/opt/pkg/petalinux/2020.1/sysroots/aarch64-xilinx-linux/lib -L/home/lsding/opt/pkg/petalinux/2020.1/sysroots/aarch64-xilinx-linux/usr/lib -o “test1.elf” ./src/test1.o /home/lsding/worksp2/libsift/Release/liblibsift.a -lopencv_core -lopencv_imgproc -lopencv_imgcodecs -lopencv_highgui -lopencv_features2d -lopencv_xfeatures2d --sysroot=/home/lsding/opt/pkg/petalinux/2020.1/sysroots/aarch64-xilinx-linux -Wl,-rpath-link=/home/lsding/opt/pkg/petalinux/2020.1/sysroots/aarch64-xilinx-linux/lib -Wl,-rpath-link=/home/lsding/opt/pkg/petalinux/2020.1/sysroots/aarch64-xilinx-linux/usr/lib
/home/lsding/opt/pkg/Vitis/2020.1/gnu/aarch64/lin/aarch64-linux/x86_64-petalinux-linux/usr/bin/aarch64-xilinx-linux/aarch64-xilinx-linux-ld.real: ./src/test1.o: in function `main’:

test1.cpp:(.text.startup+0x2b0): undefined reference to `cv::Feature2D::detectAndCompute(cv::_InputArray const&, cv::_InputArray const&, std::vector<cv::Mat

, std::allocatorcv::Mat >&, std::vector<cv::Mat, std::allocatorcv::Mat >&, std::vector<cv::KeyPoint,

std::allocatorcv::KeyPoint >&, cv::_OutputArray const&, bool)’
/home/lsding/opt/pkg/Vitis/2020.1/gnu/aarch64/lin/aarch64-linux/x86_64-petalinux-linux/usr/bin/aarch64-xilinx-linux/aarch64-xilinx-linux-ld.real: test1.cpp:(.text.startup+0x300): undefined reference to

`cv::Feature2D::detectAndCompute(cv::_InputArray const&, cv::_InputArray const&, std::vector<cv::Mat, std::allocatorcv::Mat >&, std::vector<cv::Mat, std::allocatorcv::Mat >&, std::vector<cv::KeyPoint,

I don’t want to be rude but this is not the way how you should post in such coding forums. It makes hard to understand without indentation. It would be better to post with preformatted text by adding triple backticks (a backtick is `) to start and end of a code snippet .

As far as I understand, there are some undefined reference errors which is a common trouble in c++. Ensure that you have changed source files and headers respectively. It might be you haven’t succesfully link the new lib to your project. By default it might be still linked to old version without a clean build.

PS: Delete some of your replies and merge them as just one reply with a ‘good’ formatting. for readability. Others can help too in this way.

triple backticks for blocks of code. or paste the code, select it, and use the </> icon above the text box of the post editor.