正在关注this example,
我试图构建一个应用程序来识别视频中的对象。
我的程序由以下步骤(见下面每一个步骤的代码示例):OpenCV功能检测和匹配 - 在绘图匹配上的段错误
- 阅读对象的图像被识别为
cv::Mat
对象。 - 检测对象中的关键点和计算描述符。
- 阅读视频的每个帧,
- 检测关键点,并计算帧的描述符,
- 匹配帧的对象的描述符的描述符,
- 绘图结果。
问题:第6步导致分段错误(请参阅下面的代码)。
问题:是什么原因造成的,我该如何解决?
谢谢!
注:
- 程序运行的内存设计缺陷前几帧。崩溃发生在第23帧,这是具有任何内容(即,不是完全黑色)的视频的第一帧。
- 通过删除行
drawMatches(...);
有没有崩溃。 - 在Windows 7,OpenCV 2.4.2,MinGW上运行。
Debuggind尝试:
运行通过的gdb程序产生以下消息:
Program received signal SIGSEGV, Segmentation fault.
0x685585db in _fu156___ZNSs4_Rep20_S_empty_rep_storageE() from c:\opencv\build\install\bin\libopencv_features2d242.dll
步骤1 - 读取对象的图像:
Mat object;
object = imread(OBJECT_FILE, CV_LOAD_IMAGE_GRAYSCALE);
步骤P 2 - 中的对象和计算描述符检测的关键点:
SurfFeatureDetector detector(500);
SurfDescriptorExtractor extractor;
vector<KeyPoint> keypoints_object;
Mat descriptors_object;
detector.detect(object , keypoints_object);
extractor.compute(object, keypoints_object, descriptors_object);
步骤3-6:
VideoCapture capture(VIDEO_FILE);
namedWindow("Output",0);
BFMatcher matcher(NORM_L2,true);
vector<KeyPoint> keypoints_frame;
vector<DMatch> matches;
Mat frame,
output,
descriptors_frame;
while (true)
{
//step 3:
capture >> frame;
if(frame.empty())
{
break;
}
cvtColor(frame,frame,CV_RGB2GRAY);
//step 4:
detector.detect(frame, keypoints_frame);
extractor.compute(frame, keypoints_frame, descriptors_frame);
//step 5:
matcher.match(descriptors_frame, descriptors_object, matches);
//step 6:
drawMatches(object, keypoints_object, frame, keypoints_frame, matches, output);
imshow("Output", output);
waitKey(1);
}
截图只是段错误之前:
帧22(全黑):
框架23(其中段错误发生时):
你是一个救命的人:)很多谢谢 –