Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

BFMatcher_GPU heap error

I try to run the following code based on sample "surf_keypoint_matcher.cpp". I modified the procedure which decides the input file path.

In the compile, there is no problem. When I run my program, The matching result image can be shown, but heap error is occurred (Invalid address specified to RtlValidateHeap( 0000000002370000, 000000000052E900 ).

In order to investigate the wrong line, I comment out a part of following code. When I comment out the code between "BFMatcher_GPU matcher(NORM_L2);" and "waitKey(0);", heap error isn't occurred. When I comment out the code between "GpuMat trainIdx, distance;" and "waitKey(0);", heap error is occurred. So, I think there is a trouble in the procedure "BFMatcher_GPU matcher(NORM_L2);"

I tried the version 2.5.4 and 2.5.5. I built opencv by this machine. My graphic board is NVIDIA Quadro 4000M and I use Visual Studio 2010.

Could you please give some advise for me?

#include <iostream>
#include "opencv2/opencv_modules.hpp"
#ifdef HAVE_OPENCV_NONFREE
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/gpu/gpu.hpp"
#include "opencv2/nonfree/gpu.hpp"
using namespace std;
using namespace cv;
using namespace cv::gpu;
int main(int argc, char* argv[])
{
    {
        char* img_path =    "D:\\ProgramData\\NVIDIA Corporation\\CUDA Samples\\v5.0\\0_Simple\\vectorAdd\\ransac\\samples\\KryalCastle1.jpg";
        char* target_path = "D:\\ProgramData\\NVIDIA Corporation\\CUDA Samples\\v5.0\\0_Simple\\vectorAdd\\ransac\\samples\\KryalCastle2.jpg";
        char* result_path = "D:\\ProgramData\\NVIDIA Corporation\\CUDA Samples\\v5.0\\0_Simple\\vectorAdd\\ransac\\samples\\result.jpg";
        GpuMat img1;
        img1.upload(imread(img_path, CV_LOAD_IMAGE_GRAYSCALE));
        CV_Assert(!img1.empty());
        GpuMat img2;
        img2.upload(imread(target_path, CV_LOAD_IMAGE_GRAYSCALE));
        CV_Assert(!img2.empty());
        cv::gpu::printShortCudaDeviceInfo(cv::gpu::getDevice());
        SURF_GPU surf;

        // detecting keypoints & computing descriptors
        GpuMat keypoints1GPU, keypoints2GPU;
        GpuMat descriptors1GPU, descriptors2GPU;
        surf(img1, GpuMat(), keypoints1GPU, descriptors1GPU);
        surf(img2, GpuMat(), keypoints2GPU, descriptors2GPU);
        cout << "FOUND " << keypoints1GPU.cols << " keypoints on first image" << endl;
        cout << "FOUND " << keypoints2GPU.cols << " keypoints on second image" << endl;

        // matching descriptors
        BFMatcher_GPU matcher(NORM_L2);
        GpuMat trainIdx, distance;
        matcher.matchSingle(descriptors1GPU, descriptors2GPU, trainIdx, distance);
        // downloading results
        vector<KeyPoint> keypoints1, keypoints2;
        vector<float> descriptors1, descriptors2;
        vector<DMatch> matches;
        surf.downloadKeypoints(keypoints1GPU, keypoints1);
        surf.downloadKeypoints(keypoints2GPU, keypoints2);
        surf.downloadDescriptors(descriptors1GPU, descriptors1);
        surf.downloadDescriptors(descriptors2GPU, descriptors2);
        BFMatcher_GPU::matchDownload(trainIdx, distance, matches);

        // drawing the results
        Mat img_matches;
        drawMatches(Mat(img1), keypoints1, Mat(img2), keypoints2, matches, img_matches);

        namedWindow("matches", 0);
        imshow("matches", img_matches);
        waitKey(0);
    }
return 0;
}

BFMatcher_GPU heap error

I try to run the following code based on sample "surf_keypoint_matcher.cpp". I modified the procedure which decides the input file path.

In the compile, there is no problem. When I run my program, The matching result image can be shown, but heap error is occurred (Invalid address specified to RtlValidateHeap( 0000000002370000, 000000000052E900 ).

In order to investigate the wrong line, I comment out a part of following code. When I comment out the code between "BFMatcher_GPU matcher(NORM_L2);" and "waitKey(0);", heap error isn't occurred. When I comment out the code between "GpuMat trainIdx, distance;" and "waitKey(0);", heap error is occurred. So, I think there is a trouble in the procedure "BFMatcher_GPU matcher(NORM_L2);"

I tried the version 2.5.4 and 2.5.5. I built opencv by this machine. My graphic board is NVIDIA Quadro 4000M and I use Visual Studio 2010.

Could you please give some advise for me?

#include <iostream>
#include "opencv2/opencv_modules.hpp"
#ifdef HAVE_OPENCV_NONFREE
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/gpu/gpu.hpp"
#include "opencv2/nonfree/gpu.hpp"
using namespace std;
using namespace cv;
using namespace cv::gpu;
int main(int argc, char* argv[])
{
    {
        char* img_path =    "D:\\ProgramData\\NVIDIA Corporation\\CUDA Samples\\v5.0\\0_Simple\\vectorAdd\\ransac\\samples\\KryalCastle1.jpg";
"D:\\KryalCastle1.jpg";
        char* target_path = "D:\\ProgramData\\NVIDIA Corporation\\CUDA Samples\\v5.0\\0_Simple\\vectorAdd\\ransac\\samples\\KryalCastle2.jpg";
"D:\\KryalCastle2.jpg";
        char* result_path = "D:\\ProgramData\\NVIDIA Corporation\\CUDA Samples\\v5.0\\0_Simple\\vectorAdd\\ransac\\samples\\result.jpg";
"D:\\result.jpg";
        GpuMat img1;
        img1.upload(imread(img_path, CV_LOAD_IMAGE_GRAYSCALE));
        CV_Assert(!img1.empty());
        GpuMat img2;
        img2.upload(imread(target_path, CV_LOAD_IMAGE_GRAYSCALE));
        CV_Assert(!img2.empty());
        cv::gpu::printShortCudaDeviceInfo(cv::gpu::getDevice());
        SURF_GPU surf;

        // detecting keypoints & computing descriptors
        GpuMat keypoints1GPU, keypoints2GPU;
        GpuMat descriptors1GPU, descriptors2GPU;
        surf(img1, GpuMat(), keypoints1GPU, descriptors1GPU);
        surf(img2, GpuMat(), keypoints2GPU, descriptors2GPU);
        cout << "FOUND " << keypoints1GPU.cols << " keypoints on first image" << endl;
        cout << "FOUND " << keypoints2GPU.cols << " keypoints on second image" << endl;

        // matching descriptors
        BFMatcher_GPU matcher(NORM_L2);
        GpuMat trainIdx, distance;
        matcher.matchSingle(descriptors1GPU, descriptors2GPU, trainIdx, distance);
        // downloading results
        vector<KeyPoint> keypoints1, keypoints2;
        vector<float> descriptors1, descriptors2;
        vector<DMatch> matches;
        surf.downloadKeypoints(keypoints1GPU, keypoints1);
        surf.downloadKeypoints(keypoints2GPU, keypoints2);
        surf.downloadDescriptors(descriptors1GPU, descriptors1);
        surf.downloadDescriptors(descriptors2GPU, descriptors2);
        BFMatcher_GPU::matchDownload(trainIdx, distance, matches);

        // drawing the results
        Mat img_matches;
        drawMatches(Mat(img1), keypoints1, Mat(img2), keypoints2, matches, img_matches);

        namedWindow("matches", 0);
        imshow("matches", img_matches);
        waitKey(0);
    }
return 0;
}