使用SIFT :: detect时内存不足

时间:2013-12-28 08:12:55

标签: opencv out-of-memory sift

我正在使用筛选来检测3264x2466的两个图像的关键点。以下是我的代码。但是,我收到错误消息opencv error: insufficient memory。有什么不对的吗? 以下是图片http://img42.imageshack.us/img42/6963/v839.jpg,我正在win7x86上运行该计划,opencv 2.4.7

#include <opencv\cv.h>
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <string>
#include <vector>
#include <cmath>
#include <opencv2/nonfree/features2d.hpp>
#include <opencv2/nonfree//nonfree.hpp>



using namespace std;
using namespace cv;

int main(int argc, char **argv)
{
    cv::initModule_nonfree();

    Mat image1 = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE );
    Mat image2 = imread(argv[2], CV_LOAD_IMAGE_GRAYSCALE );


    //1. compute the keypoints

    int minHessian = 400;
    Ptr<FeatureDetector> detector = FeatureDetector::create("SIFT");
    vector<KeyPoint> keypoints1,keypoints2;
    detector->detect(image1, keypoints1);
    detector->detect(image2, keypoints2);

    //2. compute the descriptor
    Ptr<DescriptorExtractor> extractor = DescriptorExtractor::create("SIFT");
    Mat descriptors1, descriptors2;

    extractor->compute( image1, keypoints1, descriptors1);
    extractor->compute( image2, keypoints2, descriptors2);



    //3. match
    Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("FlannBased");
    std::vector< DMatch > matches;
    matcher->match( descriptors1, descriptors2, matches );

    double max_dist = 0; double min_dist = 100;

    //-- Quick calculation of max and min distances between keypoints
    for( int i = 0; i < descriptors1.rows; i++ )
    { 
        double dist = matches[i].distance;
        if( dist < min_dist ) min_dist = dist;
        if( dist > max_dist ) max_dist = dist;
    }


    //-- Draw only "good" matches (i.e. whose distance is less than 2*min_dist )
    //-- PS.- radiusMatch can also be used here.
    std::vector< DMatch > good_matches;

    for( int i = 0; i < descriptors1.rows; i++ )
    { 
        if( matches[i].distance <= 2*min_dist ) { 
            good_matches.push_back( matches[i]); 
        }
    }

    //-- Draw only "good" matches
    Mat img_matches;
    drawMatches( image1, keypoints1, image2, keypoints2,
        good_matches, img_matches, Scalar::all(-1), Scalar::all(-1),
        vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );

    //-- Show detected matches
    imwrite("C:\\Users\\flex\\Desktop\\output2.jpg", img_matches);
    //imshow( "Good Matches", img_matches );

    //waitKey(0);

    return 0;
}

0 个答案:

没有答案