vendredi 3 avril 2015

SURF GPU and high definition pictures

I use SURF gpu to find transformations between two versions of the same picture.


Here is the source code :



cv::gpu::printShortCudaDeviceInfo(cv::gpu::getDevice());

int minHessian = 400;

SURF_GPU surf(minHessian);

GpuMat keypoints1GPU, keypoints2GPU;
GpuMat descriptors1GPU, descriptors2GPU;
surf(img, GpuMat(), keypoints1GPU, descriptors1GPU);
surf(img_def, GpuMat(), keypoints2GPU, descriptors2GPU);

cout << "trouve " << keypoints1GPU.cols << " keypoints sur image source" << endl;
cout << "trouve " << keypoints2GPU.cols << " keypoints sur image scannee" << endl;

// matche descripteurs
BFMatcher_GPU matcher(NORM_L2);
GpuMat trainIdx, distance;
matcher.matchSingle(descriptors1GPU, descriptors2GPU, trainIdx, distance);
// download les res sur le cpu
vector<KeyPoint> keypoints1, keypoints2;
vector<float> descriptors1, descriptors2;
vector<DMatch> matches;
vector<DMatch> good_matches;
surf.downloadKeypoints(keypoints1GPU, keypoints1);
surf.downloadKeypoints(keypoints2GPU, keypoints2);
surf.downloadDescriptors(descriptors1GPU, descriptors1);
surf.downloadDescriptors(descriptors2GPU, descriptors2);
BFMatcher_GPU::matchDownload(trainIdx, distance, matches);

//Download image gpu vers CPU
Mat imgcpu, imgcpu_def;
img.download(imgcpu);
img_def.download(imgcpu_def);
Mat out, out_def, out_f, out_f_gm;

std::vector<Point2f> origi;
std::vector<Point2f> scan;
for (int i = 0; i < matches.size(); i++)
{
//extraire les keypoint des good matches
origi.push_back(keypoints1[matches[i].queryIdx].pt);
scan.push_back(keypoints2[matches[i].trainIdx].pt);
}
cout << "Good matches :" << matches.size() << endl;

GpuMat img_ref(img_def.rows, img_def.cols, img_def.type());
img_ref.setTo(Scalar::all(0));
Mat H = findHomography(origi, scan, CV_RANSAC);
Scalar blanc(255, 255, 255);
cv::gpu::warpPerspective(img_vernis, img_ref, H, img_def.size(), INTER_NEAREST, BORDER_CONSTANT, blanc);
Mat sortie;
img_ref.download(sortie);

// drawing the results
Mat img_matches;
drawMatches(Mat(img), keypoints1, Mat(img_def), keypoints2, matches, img_matches);
namedWindow("matches", CV_WINDOW_NORMAL);
imshow("matches", img_matches);
namedWindow("deformations", CV_WINDOW_NORMAL);
imshow("deformations", sortie);

waitKey(0);


So when I run the code with pictures up to 3k it works fine but if I use pictures biggers then 4000*4000 pixels the program crash. The error : Error api cuda


Is there a limit of size in SURF gpu or BFMatcher_GPU?


Aucun commentaire:

Enregistrer un commentaire