ChangEyes 2015-05-10 01:24 采纳率: 10.5%
浏览 2559

调用摄像头做surf特征点识别

程序如下,编译成功,运行了就中断。把这段程序移植到其他程序后,还是一样的问题,前两张图片可以,第三张图片就中断了为什么。。。。。。?
大神们,帮帮忙,谢谢~

#include "stdafx.h"

#include

#include "opencv2/core/core.hpp"

#include "opencv2/features2d/features2d.hpp"

#include "opencv2/highgui/highgui.hpp"

#include "opencv2/nonfree/features2d.hpp"

#include "opencv2/calib3d/calib3d.hpp"

#include "opencv2/imgproc/imgproc.hpp"

using namespace cv;

using namespace std;

int _tmain(int argc, _TCHAR* argv[])

{

VideoCapture cap(0);
if (!cap.isOpened())
{
cout<<"cap open failed!!!";
return -1;

}
cout<<"cap open success"<<endl;

    Mat img_1 = imread( "d:/3.jpg", CV_LOAD_IMAGE_GRAYSCALE );  
    //Mat img_2 = imread( "d:/4.jpg", CV_LOAD_IMAGE_GRAYSCALE );  
    Mat img_22;
    Mat img_2;

for (;;)
{
cap >> img_22;
cvtColor(img_22,img_2,CV_BGR2GRAY);

    if( !img_1.data || !img_2.data )  
    { return -1; }  

    //-- Step 1: Detect the keypoints using SURF Detector  
    //Threshold for hessian keypoint detector used in SURF  
    int minHessian = 1500;  

    SurfFeatureDetector detector( minHessian );  

    std::vector<KeyPoint> keypoints_1, keypoints_2;  

    detector.detect( img_1, keypoints_1 );  
    detector.detect( img_2, keypoints_2 );  

    //-- Step 2: Calculate descriptors (feature vectors)  
    SurfDescriptorExtractor extractor;  

    Mat descriptors_1, descriptors_2;  

    extractor.compute( img_1, keypoints_1, descriptors_1 );  
    extractor.compute( img_2, keypoints_2, descriptors_2 );  

    //-- Step 3: Matching descriptor vectors with a brute force matcher  
    BFMatcher matcher(NORM_L2,false);  
    //FlannBasedMatcher matcher1;  
    vector< DMatch > matches;  
    vector<vector< DMatch >> matches2;  
    matcher.match( descriptors_1, descriptors_2, matches );  

    //matcher1.match(descriptors_1, descriptors_2, matches );  

    const float minRatio = 1.f / 1.5f;  
    matches.clear();  
    matcher.knnMatch(descriptors_1, descriptors_2,matches2,2);  
    for (size_t i=0; i<matches2.size(); i++)  
    {  
            const cv:Match& bestMatch = matches2[i][0];  
            const cv:Match& betterMatch = matches2[i][1];  
            float distanceRatio = bestMatch.distance /betterMatch.distance;  
            // Pass only matches where distance ratio between  
            // nearest matches is greater than 1.5  
            // (distinct criteria)  
            if (distanceRatio < minRatio)  
            {  
                    matches.push_back(bestMatch);  
            }  
    }  

    //-- Draw matches  
    Mat img_matches;  
    drawMatches( img_1, keypoints_1, img_2, keypoints_2, matches, img_matches );  

    //-- Show detected matches  
    imshow("Matches", img_matches );  

    if(waitKey(30)>=0)
    break;

}
return 0;
}

图片说明

  • 写回答

1条回答 默认 最新

  • threenewbee 2015-05-10 01:28
    关注

    点retry
    然后选择调试,找到报错的断言和所在的代码行,才好判断

    评论

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计