komrad36 / cudak2nn Goto Github PK
View Code? Open in Web Editor NEWInsanely fast CUDA 2NN 512-bit binary descriptor matcher for computer vision
License: MIT License
Insanely fast CUDA 2NN 512-bit binary descriptor matcher for computer vision
License: MIT License
g++ -c -I/usr/local/cuda/include/ -Wall -Wextra -Werror -Wshadow -pedantic -Ofast -std=gnu++17 -fomit-frame-pointer -march=native -flto -funroll-all-loops -fpeel-loops -ftracer -ftree-vectorize main.cpp -o main.o
nvcc --use_fast_math -arch=sm_30 -O3 -ccbin cc -std=c++11 -c -I/usr/local/cuda/include/ -Xcompiler "-Wall -Wextra -Werror -Wshadow -Ofast -fomit-frame-pointer -march=native -funroll-all-loops -fpeel-loops -ftracer -ftree-vectorize" CUDAK2NN.cu -o CUDAK2NN.o
/usr/include/string.h: In function ‘void* __mempcpy_inline(void*, const void*, size_t)’:
/usr/include/string.h:652:42: error: ‘memcpy’ was not declared in this scope
return (char *) memcpy (__dest, __src, __n) + __n;
I'm integrating koral into another project. The results of k2nn are really strange.
here's code snip
CUDAK2NN(d_desc1, static_cast<int>(kpSize1), tex_q, static_cast<int>(kpSize2), d_matches, matchThreshold); // kpSize1 kpSize2
// transferring matches back to host
int* h_matches = reinterpret_cast<int*>(malloc(4 * kpSize2)); // kpSize2
cudaMemcpy(h_matches, d_matches, 4 * kpSize2, cudaMemcpyDeviceToHost); // kpSize2
for (size_t i = 0; i < maxkpNum; ++i) {
if (h_matches[i] != -1) { // h_matches[i] >= 0
kMatches.emplace_back(i, h_matches[i]);
}
printf("h_match=%i \n", h_matches[i]);
}
and here's a snip of the the printf statement
h_match=1073743776
h_match=32661
h_match=1073743776
h_match=32661
h_match=1081027728
h_match=32661
h_match=1081027728
h_match=32661
h_match=1077809840
h_match=32661
h_match=1073741952
h_match=32661
h_match=0
h_match=0
Am I mistaken by, expecting h_match[i] to equal an index of a corresponding descriptor?
Hello,
I am trying to test the combination of KORAL and CUDAK2NN for detection and matching. I am able to get KORAL working to detect and describe keypoints in two images, and I believe CUDAK2NN is working fine too, but I am having trouble actually retrieving the matches and drawing them. For a sample, I tried the simplest case: matching between the same image. I tried to follow your sample code from this link.
memset(&resDesc, 0, sizeof(resDesc));
resDesc.resType = cudaResourceTypeLinear;
resDesc.res.linear.devPtr = &koral.desc[0];
resDesc.res.linear.desc.f = cudaChannelFormatKindUnsigned;
resDesc.res.linear.desc.x = 32;
resDesc.res.linear.desc.y = 32;
resDesc.res.linear.sizeInBytes = 64 * koral.kps.size();
struct cudaTextureDesc texDesc;
memset(&texDesc, 0, sizeof(texDesc));
texDesc.addressMode[0] = cudaAddressModeBorder;
texDesc.addressMode[1] = cudaAddressModeBorder;
texDesc.filterMode = cudaFilterModePoint;
texDesc.readMode = cudaReadModeElementType;
texDesc.normalizedCoords = 0;
cudaTextureObject_t tex_q = 0;
cudaCreateTextureObject(&tex_q, &resDesc, &texDesc, nullptr);
int* d_matches;
cudaMalloc(&d_matches, 4 * koral.kps.size());
CUDAK2NN(&koral.desc[0], static_cast<int>(koral.kps.size()), tex_q, static_cast<int>(koral.kps.size()), d_matches, 5);
int* h_matches = reinterpret_cast<int*>(malloc(4 * koral.kps.size()));
cudaMemcpy(h_matches, d_matches, 4 * koral.kps.size(), cudaMemcpyDeviceToHost);
cudaDeviceReset();
std::cout << "CUDA reports " << cudaGetErrorString(cudaGetLastError()) << std::endl;
std::vector<Match> matches;
std::vector<cv::DMatch> dmatches;
for (int i = 0; i < koral.kps.size(); ++i) {
if (h_matches[i] != -1) {
matches.emplace_back(i, h_matches[i]);
dmatches.emplace_back(h_matches[i], i, 0.0f);
}
}
std::cout << "CUDAK2NN found " << matches.size() << " matches." << std::endl;
std::cout << static_cast<int>(converted_kps.size()) << std::endl;
cv::Mat image_with_matches;
cv::drawMatches(image, converted_kps, image, converted_kps, dmatches, image_with_matches, cv::Scalar::all(-1.0), cv::Scalar::all(-1.0), std::vector<char>(), cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
cv::namedWindow("Matches", CV_WINDOW_NORMAL | CV_WINDOW_KEEPRATIO);
cv::imshow("Matches", image_with_matches);
cv::waitKey(0);
The output from the detection and matching is exactly as expected:
KORAL found 30994 keypoints and descriptors.
CUDA reports no error
CUDAK2NN found 30993 matches.
But I seem to be making a mistake in retrieving the matches, because h_matches
is just full of junk values which eventually causes drawMatches
to fail. Could you please let me know where I am going wrong with that? Thanks a lot!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.