【发布时间】:2014-02-12 22:06:41
【问题描述】:
取样本点 (10,10), (20,0), (20,40), (20,20)。
在 Matlab 中 polyfit 返回斜率 1,但对于相同的数据 openCV fitline 返回斜率 10.7。根据手工计算,接近垂直线(斜率 10.7)的最小二乘拟合要好得多。
为什么我们从两个库中得到不同的行?
OpenCV 代码 - (在 iOS 上)
vector<cv::Point> vTestPoints;
vTestPoints.push_back(cv::Point( 10, 10 ));
vTestPoints.push_back(cv::Point( 20, 0 ));
vTestPoints.push_back(cv::Point( 20, 40 ));
vTestPoints.push_back(cv::Point( 20, 20 ));
Mat cvTest = Mat(vTestPoints);
cv::Vec4f testWeight;
fitLine( cvTest, testWeight, CV_DIST_L2, 0, 0.01, 0.01);
NSLog(@"Slope: %.2f",testWeight[1]/testWeight[0]);
xcode 日志显示
2014-02-12 16:14:28.109 Application[3801:70b] Slope: 10.76
Matlab 代码
>> px
px = 10 20 20 20
>> py
py = 10 0 20 40
>> polyfit(px,py,1)
ans = 1.0000e+000 -2.7733e-014
【问题讨论】:
-
坡度
10.76- 偏移量是多少? -
Matlab/polyfit - 穿过 (10,10) 的线,斜率 1.0。 --- openCV/fitline - 穿过 (17.5,17.5) 的线,坡度 10.76。