Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get the coordinate of feature points of popsift::FeaturesDev? #91

Closed
BruceXSK opened this issue May 3, 2020 · 4 comments
Closed

Comments

@BruceXSK
Copy link

BruceXSK commented May 3, 2020

I want to get the coordinate of feature points after match. So I add cout << lFeatures->getFeatures()[0].xpos << endl; to src/application/match.cpp. Then the program broke. It shows Segmentation fault (core dumped).
But I did the same thing to src/application/main.cpp, added cout << feature_list->_ext[0].xpos << endl; to void read_job( SiftJob* job, bool really_write ), it worked well.
I noticed that the class of lFeatures is popsift::FeaturesDev, and the feature_list's is popsift::Features. So why I cannot get the infomation of feature from popsift::FeaturesDev? What should I do? THANKS!

@griwodz
Copy link
Member

griwodz commented May 4, 2020

The FeaturesDev memory exists only in GPU memory, not in the CPU memory. To use the coordinates in the CPU after matching, you must transfer them first.

You could do something like this:

    FeaturesHost* features = new FeaturesHost( lFeatures->getFeatureCount(), lFeatures->getDescriptorCount() );
    features->pin( );
    cudaMemcpy( features->getFeatures(),
                             lFeatures->getFeatures();
                             lFeatures->getFeatureCount() * sizeof(Feature),
                             cudaMemcpyDeviceToHost );
    cudaMemcpy( features->getDescriptors(),
                             lFeatures->getDescriptors(),
                             lFeatures->getDescriptorCount() * sizeof(Descriptor),
                             cudaMemcpyDeviceToHost );
    features->unpin( );

@BruceXSK
Copy link
Author

BruceXSK commented May 4, 2020

The FeaturesDev memory exists only in GPU memory, not in the CPU memory. To use the coordinates in the CPU after matching, you must transfer them first.

You could do something like this:

    FeaturesHost* features = new FeaturesHost( lFeatures->getFeatureCount(), lFeatures->getDescriptorCount() );
    features->pin( );
    cudaMemcpy( features->getFeatures(),
                             lFeatures->getFeatures();
                             lFeatures->getFeatureCount() * sizeof(Feature),
                             cudaMemcpyDeviceToHost );
    cudaMemcpy( features->getDescriptors(),
                             lFeatures->getDescriptors(),
                             lFeatures->getDescriptorCount() * sizeof(Descriptor),
                             cudaMemcpyDeviceToHost );
    features->unpin( );

I tried and it worked! Thank you so much!

@BruceXSK BruceXSK closed this as completed May 4, 2020
@gloria111
Copy link

gloria111 commented Mar 15, 2022

it works,thanks

@gloria111
Copy link

I try to get all the descriptors and feature points on the CPU with following codes
std::unique_ptr<popsift::Features> sf;
sf.reset(sfeatures);
popsift::Feature* sfeature_list = sf->getFeatures();
std::vector<float> spoints(4 * numFeatures);
std::vector<float> sdesc(128 * numFeatures);
int width = 1920;
int height = 1080;

for(size_t i = 0; i < numFeatures; i++) { popsift::Feature pFeat = sfeature_list[i];
but the program crashes when i try to print the descriptors.

    cout << "pFeat.desc->features:" << ((pFeat.desc[0])->features[0[)<< endl;
    for(int oriIdx = 0; oriIdx < pFeat.num_ori; oriIdx++)
    {
        const popsift::Descriptor* pDesc = pFeat.desc[oriIdx];
        cout << "note here :" << ((pDesc->features)[0]) << endl;
        for(int k = 0; k < 128; k++)
        {
            sdesc[128 * i + k] = pDesc->features[k]; //==(*pDesc).features[k]
        }

        spoints[4 * i + 0] = std::min<float>(std::round(pFeat.xpos), width - 1);
        spoints[4 * i + 1] = std::min<float>(std::round(pFeat.ypos), height - 1);
        spoints[4 * i + 2] = pFeat.sigma;
        spoints[4 * i + 3] = pFeat.orientation[oriIdx];
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants