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 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题