Eya*_*lAr 4 c++ opencv object-detection segmentation-fault surf
在这个例子之后,
我正在尝试构建一个应用程序来识别视频中的对象.
我的程序由以下步骤组成(请参阅下面每个步骤的代码示例):
cv::Mat对象中.问题:第6步导致分段错误(参见下面的代码).
问题:是什么导致它,我该如何解决?
谢谢!
笔记:
drawMatches(...);有没有崩溃.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
Run Code Online (Sandbox Code Playgroud)
第1步 - 读取对象的图像:
Mat object;
object = imread(OBJECT_FILE, CV_LOAD_IMAGE_GRAYSCALE);
Run Code Online (Sandbox Code Playgroud)
第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);
Run Code Online (Sandbox Code Playgroud)
步骤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);
}
Run Code Online (Sandbox Code Playgroud)
在segfault之前的屏幕截图:

第22帧(全黑):

第23帧(发生段错误):

问题在于参数的顺序drawMatches.
正确的顺序是:
drawMatches(frame, keypoints_frame, object, keypoints_object, matches, output);
Run Code Online (Sandbox Code Playgroud)
说明:
在第5步中,我正在使用对象的match方法matcher:
matcher.match(descriptors_frame, descriptors_object, matches);
Run Code Online (Sandbox Code Playgroud)
void match( const Mat& queryDescriptors, const Mat& trainDescriptors,
CV_OUT vector<DMatch>& matches, const Mat& mask=Mat() ) const;
Run Code Online (Sandbox Code Playgroud)
这意味着,matches包含比赛从 trainDescriptors 到 queryDescriptors.
在我的情况下,列车描述符的object和查询描述符的frame,所以matches包含比赛从该object 到了frame.
签名的drawMatchesIS
void drawMatches( const Mat& img1, const vector<KeyPoint>& keypoints1,
const Mat& img2, const vector<KeyPoint>& keypoints2,
const vector<DMatch>& matches1to2,
... );
Run Code Online (Sandbox Code Playgroud)
drawMatches使用不正确的参数顺序调用时:
drawMatches(object, keypoints_object, frame, keypoints_frame, matches, output);
Run Code Online (Sandbox Code Playgroud)
该方法在不正确的图像中查找匹配的坐标,这可能导致尝试访问"越界"像素; 因此分割错误.
| 归档时间: |
|
| 查看次数: |
4002 次 |
| 最近记录: |