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