开发者

detector->detect(img, keypoint); error

I want to implement bag of words in opencv. after detector->detect(img, keypoint); detects keypoints, when i want to clean keypoints using keypoint.clear(); or when the function wants to return the following error will be appeared.

"Unhandled exception at 0x011f45bb in BOW.exe: 0xC0000005: Access violation reading location 0x42ebe098."

and also detected keypoints have bizarre points coordinates like cv::Point_ pt{x=-1.5883997e+038y=-1.5883997e+038 }

Part of the code

Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("FlannBased");
Ptr<DescriptorExtractor> extractor = new SurfDescriptorExtractor();
Ptr开发者_JS百科<FeatureDetector> detector = new SurfFeatureDetector(2000);
    void extractTrainingVocabulary() {
        IplImage *img;
        int i,j;
         CvSeq *imageKeypoints = 0;
        for(j=1;j<=60;j++)
        for(i=1;i<=60;i++){
            sprintf( ch,"%d%s%d%s",j," (",i,").jpg");
                        const char* imageName = ch;
                        Mat img = imread(ch);
                        vector<KeyPoint> keypoint;
                        detector->detect(img, keypoint);
                        Mat features;
                        extractor->compute(img, keypoint, features);
                        bowTrainer.add(features);
                        keypoint.clear();//problem
        }
    return;
    }


I noticed something about your code, on extractTrainingVocabulary() you declare IplImage* img; and inside the loop you declare another variable with the same name (but different type): Mat img = imread(ch);.

Even though that might not be the problem, it's certainly not good practice. I would fix that immediately and update the code on your question.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜