我试图在视觉工作室2017中将两张图片与opencv3的orb相匹配。首先,我从一个txt文件中读取灰色图像矩阵为64x64灰色图片,然后我预先处理图像。图像被成功读取,但是当我即将使用orb的检测功能时,会发生错误,我不知道出了什么问题。这是我的代码:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include<opencv2\opencv.hpp>
#include<fstream>
#include<iostream>
#include <time.h>
#define rows 64
#define cols 64
#define MAXV 100
using namespace cv;
using namespace std;
int main()
{
int grey, i, j;
char div;
float x1, y1, x2, y2, vx, vy, vxbar, vybar;
clock_t tm1, tm2, tm3, tm4;
fstream file;
file.open("gray.txt");
Mat img_1 = Mat::zeros(rows, cols, CV_8UC1);
Mat img_2 = Mat::zeros(rows, cols, CV_8UC1);
Mat img_blur = Mat::zeros(rows, cols, CV_8UC1);
for (i = 0; i < rows; i++)
{
for (j = 0; j < cols - 1; j++)
{
//file >> TrainData.at<float>(i, j);
file >> grey >> div;
img_1.at<uchar>(i, j) = grey;
}
file >> grey;
img_1.at<uchar>(i, cols - 1) = grey;
}
for (i = 0; i < rows; i++)
{
for (j = 0; j < cols - 1; j++)
{
file >> grey >> div;
img_2.at<uchar>(i, j) = grey;
}
file >> grey;
img_2.at<uchar>(i, cols - 1) = grey;
}
equalizeHist(img_1, img_1);
equalizeHist(img_2, img_2);
vector<KeyPoint> keypoints_1, keypoints_2;
Ptr<ORB> orb = ORB::create(500, 1.2f, 1, 7, 0, 2, ORB::HARRIS_SCORE, 23, 1);
orb->detect(img_1, keypoints_1);
orb->detect(img_2, keypoints_2);
// -- Stpe 2: Calculate descriptors (feature vectors)
Mat descriptors_1, descriptors_2;
orb->compute(img_1, keypoints_1, descriptors_1);
orb->compute(img_2, keypoints_2, descriptors_2);
以下是错误报告的截图:
相关代码是
orb->detect(img_1, keypoints_1);
和错误报告:
install and test opencv.exe has triggered a breakpoint. occurred