opencv cvfitline给出了令人怀疑的结果

时间:2012-03-26 22:06:05

标签: opencv line curve-fitting data-fitting

我正在使用OpenCV的函数cvFitLine,它给我的结果我觉得非常值得怀疑。基本上,你可以看到我几乎沿着一条带有2个异常值的线输入点的坐标。我使用Huber距离测量来忽略异常值。然而,由此产生的拟合线是一条对角线,似乎非常考虑了异常值。难道我做错了什么?是否有人得到类似的结果?

(编辑)结果显然应该是一条类似于{vx,vy,x0y0} = {0,1,531,0}的直线,但openCV给我{0.85,-0.53,453,144}这不是远程垂直的。< / p>

CvPoint * points=(CvPoint*)malloc( 13 * sizeof(points[0]));

points[0].x = 531;points[0].y = 0;
points[1].x = 531;points[1].y = 20;
points[2].x = 530;points[2].y = 40;
points[3].x = 531;points[3].y = 60;
points[4].x = 530;points[4].y = 80;
points[5].x = 531;points[5].y = 100;
points[6].x = 531;points[6].y = 120;
points[7].x = 531;points[7].y = 140;
points[8].x = 531;points[8].y = 160;
points[9].x = 531;points[9].y = 180;
points[10].x = 531;points[10].y = 200;
points[11].x = 273;points[11].y = 260;
points[12].x = 141;points[12].y = 280;
float testPar[4];// to store the results
CvMat point_mat = cvMat( 1, 13, CV_32SC2, points );
cvFitLine(&point_mat,CV_DIST_HUBER ,0,0.01,0.01,testPar);

1 个答案:

答案 0 :(得分:-1)

如果您注意到有两个x坐标值为530,则它们没有正确输入坐标,而它们应该是531.这两个点出现故障(即值为530的点)。其余的都没问题。