简体   繁体   English

使用OpenCV,C ++的桑普森距离

[英]Sampson Distance using opencv, c++

I'm trying to calculate the Sampson distance , the distance from a point to it's corresponding epipolar line which I will use as an error metric later. 我正在尝试计算Sampson distance ,即从一个点到其对应的对极线的距离,以后将用作误差度量。 I'm using opencv 3.1 , c++ , and windows-10 visual studio 14 . 我正在使用opencv 3.1c++windows-10 visual studio 14

But the function sampsonDistance crashes the code: 但是函数sampsonDistance使代码崩溃:

Point3f point1 = Point3f(keypoints_1[good_matches[iP].queryIdx].pt.x, keypoints_1[good_matches[iP].queryIdx].pt.y, 1.0);
Point3f point2 = Point3f(keypoints_2[good_matches[iP].trainIdx].pt.x, keypoints_2[good_matches[iP].trainIdx].pt.y, 1.0);            

Mat pt1(point1);
Mat pt2(point2);

double sampsonD = sampsonDistance(pt1, pt2, Flist[iF])

I get the error message: 我收到错误消息:

OpenCV Error: Assertion failed (_pt1.type() == CV_64F && _pt1.type() == CV_64F && _F.type() == CV_64F) in cv::sampsonDistance, file D:\opencv\sources\modules\calib3d\src\fundam.cpp, line 1043

The documentation says: 该文件说:

double cv::sampsonDistance  ( InputArray  pt1,  
InputArray  pt2,  
InputArray  F  
) 

How do I use this function, I don't really understand the usage of the input array, in the above I convert a 3d point into what I believe is 2D homogeneous coordinates stored as a cv::Mat. 我如何使用此函数,我不太了解输入数组的用法,在上面我将3d点转换为我认为是存储为cv :: Mat的2D齐次坐标。 The fundamental matrix is stored at a 3x3 cv::Mat. 基本矩阵存储在3x3 cv :: Mat中。

From the error message, the points and the fundamental matrix have to be CV_64F (double type). 根据错误消息,这些点和基本矩阵必须为CV_64F (双CV_64F型)。

For the points, it should be: 对于这些要点,应为:

Point3d point1 = Point3d(keypoints_1[good_matches[iP].queryIdx].pt.x, keypoints_1[good_matches[iP].queryIdx].pt.y, 1.0);
Point3d point2 = Point3d(keypoints_2[good_matches[iP].trainIdx].pt.x, keypoints_2[good_matches[iP].trainIdx].pt.y, 1.0);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM