gpt4 book ai didi

c++ - 带有 SURF 的 OpenCV C++ 'Access Violation'

转载 作者:太空宇宙 更新时间:2023-11-04 13:49:25 25 4
gpt4 key购买 nike

我正在尝试使用 SURF 特征检测器,但我总是遇到这个错误-

程序“[1120] Corner Detection.exe”已退出,代码为 -1073741819 (0xc0000005)“访问冲突”。

这是代码

#include "stdafx.h"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/nonfree/features2d.hpp"
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <stdio.h>
#include "opencv2/core/core.hpp"
#include "opencv2\nonfree\nonfree.hpp"

using namespace cv;
using namespace std;

void foo(Mat &image1, Mat &image2)
{
int minHeassian = 400;

SurfFeatureDetector detector(minHeassian);

std::vector< KeyPoint > keypoints1, keypoints2;

keypoints1.resize(1000);
keypoints2.resize(1000);

detector.detect(image1, keypoints1); // <--- crashes at this line
detector.detect(image2, keypoints2); // <--- probably will crash here too

SurfDescriptorExtractor extractor;

Mat discriptors1, discriptors2;

extractor.compute(image1, keypoints1, discriptors1);
extractor.compute(image2, keypoints2, discriptors2);

FlannBasedMatcher matcher;

std::vector< DMatch > matches;

matcher.match(discriptors1, discriptors2, matches);

double minDist = 100;

for (int i = 0; i < matches.size(); ++i)
if (matches[i].distance < minDist)
minDist = matches[i].distance;

std::vector< DMatch > goodMatches;

for (int i = 0; i < matches.size(); ++i)
if (matches[i].distance <= max(0.02, (double)matches[i].distance))
goodMatches.push_back(matches[i]);

Mat matchImage;

drawMatches(image1, keypoints1, image2, keypoints2,
goodMatches, matchImage,
Scalar::all(-1), Scalar::all(-1), vector<char>(),
DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);

namedWindow("Matches", WINDOW_AUTOSIZE);
imshow("Matches", matchImage);

waitKey(0);

}

int _tmain(int argc, _TCHAR* argv[])
{
cv::initModule_nonfree();

Mat left, right;
right = imread("D:\\right.jpg", IMREAD_COLOR);
left = imread("D:\\left.jpg", IMREAD_COLOR);
foo(left, right);
return 0;
}

我在行中收到错误

detector.detect(image1, keypoints1);

我有以下链接器提到的 lib 文件-

opencv_core249d.lib
opencv_imgproc249d.lib
opencv_highgui249d.lib
opencv_ml249d.lib
opencv_video249d.lib
opencv_features2d249d.lib
opencv_calib3d249d.lib
opencv_objdetect249d.lib
opencv_contrib249d.lib
opencv_legacy249d.lib
opencv_flann249d.lib
opencv_features2d249.lib
opencv_nonfree249.lib

我已经尝试了我在 Internet 上找到的所有方法,但没有任何效果。这段代码有什么问题?

我在 Windows 8.1 上运行 VS 2013,我使用的是 OpenCV 2.4.9 版。

已解决

这是一个愚蠢的错误。我使用了库 opencv_nonfree249.lib 而我应该使用 opencv_nonfree249**d**.lib 因为我在 Debug模式下工作。

最佳答案

您在用于发布环境的调试环境中使用库 opencv_nonfree249.lib。将 d 添加到 lib 名称,使其成为 opencv_nonfree249d.lib,这将适用于调试环境。

关于c++ - 带有 SURF 的 OpenCV C++ 'Access Violation',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24129044/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com