Celebrandil / CudaSift

A CUDA implementation of SIFT for NVidia GPUs (1.2 ms on a GTX 1060)
MIT License
864 stars 286 forks source link

Why I can't get any match correspondence even with the same images? #47

Open yiran-THU opened 6 years ago

yiran-THU commented 6 years ago

Thank you for sharing this implementaion!

Environment

Current Behavior:

I have successfully build this repository with no errors. I have tested mainSift.cpp with the same image (limg and rimg are the same picture) many times, none of them get any match correspondence! I never chenge the code of mainSift.cpp.

Here is My output of mainSift.cpp:

Image size = (812,725)
Initializing data...
Device Number: 0
  Device name: GeForce GTX 1060
  Memory Clock Rate (MHz): 4004
  Memory Bus Width (bits): 192
  Peak Memory Bandwidth (GB/s): 192.2

SIFT extraction time =        1.99 ms
Incl prefiltering & memcpy =  3.09 ms 2623

SIFT extraction time =        1.82 ms
Incl prefiltering & memcpy =  3.06 ms 2624

MatchSiftData time =          6.16 ms
...
MatchSiftData time =          4.85 ms
Number of original features: 2623 2624
Number of matching features: 0 0 0% 1 3

Expected Behavior:

I expect CUDAsift find the correct correspondence , and show the correspondence between model image and test image.

Besides, the finding homography process is based on both model image's feature and test image's feature. Why there is only siftData1 input to functionFindHomography and ImproveHomography in mainSift.cpp?

for (int i = 0; i<500; i++)
  MatchSiftData(siftData1, siftData2);
float homography[9];
int numMatches;
FindHomography(siftData1, homography, &numMatches, 10000, 0.00f, 0.80f, 5.0);
int numFit = ImproveHomography(siftData1, homography, 5, 0.00f, 0.80f, 3.0);

I have been troubling in above two problems several days, can you help me for any suggestion? Thank you!

Celebrandil commented 6 years ago

That is weird. Could you upload the image? I cannot verify it. It might be something related to the unusual image size, but that seems like something I should have noticed before then.

Celebrandil commented 6 years ago

By the way, MatchSiftData uses both siftData1 and siftData2. It will create per feature cross-references, which means that FindHomography and ImproveHomography won't need siftData2.

yiran-THU commented 6 years ago

@Celebrandil I think something is wrong in the procedure of MatchSiftData of my computer. I have modified the mainSift.cpp, my test code fragment is shown below:

    ExtractSift(siftData1, img1, 5, initBlur, thresh, 0.0f, false, memoryTmp);
    ExtractSift(siftData2, img2, 5, initBlur, thresh, 0.0f, false, memoryTmp);

    FreeSiftTempMemory(memoryTmp);

    MatchSiftData(siftData1, siftData2);

        showCorrespondence(siftData1, siftData2, limg_0, rimg_0);

void showCorrespondence(SiftData &siftData1, SiftData &siftData2, cv::Mat limg_0, cv::Mat rimg_0)
{
    int numPts = siftData1.numPts;
    SiftPoint *sift1 = siftData1.h_data;
    SiftPoint *sift2 = siftData2.h_data;

    int w = limg_0.size().width;
    int h = limg_0.size().height;

    cv::resize(rimg_0, rimg_0, cv::Size(w, h));

    cv::Mat img_m = cv::Mat::zeros(h , 2*w,CV_8UC3);
    limg_0.copyTo(img_m(cv::Rect(0,0,w,h)));
    rimg_0.copyTo(img_m(cv::Rect(w,0,w,h)));

    std::cout << sift1[1].xpos << ", " << sift1[1].ypos << std::endl;
    for (int j = 0; j < numPts; j++)
    {
        int k = sift1[j].match;
        if (sift1[j].match_error < 5)
        {
            cv::circle(img_m, cv::Point(sift1[j].xpos, sift1[j].ypos),2,cv::Scalar(60, 20, 220),2);
            cv::circle(img_m, cv::Point(sift1[j].match_xpos + w, sift1[j].match_ypos), 2, cv::Scalar(173, 216, 230),2);
            std::cout << sift1[j].match_xpos << ", " << sift1[j].match_ypos << std::endl;
            cv::line(img_m,cv::Point(sift1[j].xpos, sift1[j].ypos),cv::Point(sift1[j].match_xpos + w, sift1[j].match_ypos),cv::Scalar(0,255,0),1);
        }
    }

    cv::namedWindow("Result");
    cv::resizeWindow("Result",cv::Size(600,300));
    cv::imshow("Result",img_m);
    cv::waitKey();
}

The result picture is _20181030114552

Celebrandil commented 6 years ago

Unfortunately, I cannot verify it on my machine with the images from the data/ directory, even with your showCorrespondence function. Weird.

img_m

yiran-THU commented 6 years ago

@Celebrandil what's the CUDA version are you use?

yiran-THU commented 6 years ago

Here is my result. result

yangninghua commented 6 years ago

@Celebrandil what's the CUDA version are you use?

Hello yiran-THU, can you send me a copy of my version, I have the same configuration as you, but my failure to compile successfully My email is lgdyangninghua@hotmail.com

yangninghua commented 6 years ago

Here is my result. result

Building NVCC (Device) object CMakeFiles/cudasift.dir/Debug/cudasift_generated_cudaImage.cu.obj nvcc fatal : redefinition of argument 'gpu-architecture' CMake Error at cudasift_generated_cudaImage.cu.obj.Debug.cmake:219 (message): Error generating E:/ynh/c2/build/CMakeFiles/cudasift.dir//Debug/cudasift_generated_cudaImage.cu.obj

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(171,5): error MSB6006: “cmd.exe”

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(171,5): error MSB6006: “cmd.exe”

gmcgrath-lakehead commented 5 years ago

Building NVCC (Device) object CMakeFiles/cudasift.dir/Debug/cudasift_generated_cudaImage.cu.obj nvcc fatal : redefinition of argument 'gpu-architecture' CMake Error at cudasift_generated_cudaImage.cu.obj.Debug.cmake:219 (message): Error generating E:/ynh/c2/build/CMakeFiles/cudasift.dir//Debug/cudasift_generated_cudaImage.cu.obj

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(171,5): error MSB6006: “cmd.exe”

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(171,5): error MSB6006: “cmd.exe”

Please see my comment here. I used this method today to get everything to successfully compile on Windows 10.

EDIT: The version of Visual Studio doesn't matter. I managed to get everything to work in VS2017. The solution that I ended up with was the method mentioned in my other comment where I modified the architecture value from the code supplied by Celebrandil. I have a GT640 graphics card so I had to use the lowest available architecture value which I believe is 3.0 (even though the website says 2.1 CUDA only supports as low as 3.0 now.)

mintisan commented 5 years ago

@yangninghua remove duplicated flag -arch=sm_62 works for me