van*_*act 8 opencv image-processing shape ellipse
我正在使用opencv,我需要了解fitEllipse函数是如何工作的.我查看了(https://github.com/Itseez/opencv/blob/master/modules/imgproc/src/shapedescr.cpp)的代码,我知道它使用最小二乘来确定可能的椭圆.我还查看了文档中给出的文件(Andrew W. Fitzgibbon,RBFisher.一个买方的Conic Fitting指南.Proc.5th British Machine Vision Conference,Birmingham,pp.513-522,1995.)
但我无法完全理解算法.例如,为什么它需要解决3倍最小二乘问题?为什么bd在第一个svd之前被初始化为10000(我猜它是juste初始化的一个随机值,但为什么这个值可以是随机的?)?为什么广告中的值在第一个svd之前需要为负数?
谢谢!
这是Matlab代码..它可能会有所帮助
function [Q,a]=fit_ellipse_fitzgibbon(data)
% function [Q,a]=fit_ellipse_fitzgibbon(data)
%
% Ellipse specific fit, according to:
%
% Direct Least Square Fitting of Ellipses,
% A. Fitzgibbon, M. Pilu and R. Fisher. PAMI 1996
%
%
% See Also:
% FIT_ELLIPSE_LS
% FIT_ELLIPSE_HALIR
[m,n] = size(data);
assert((m==2||m==3)&&n>5);
x = data(1,:)';
y = data(2,:)';
D = [x.^2 x.*y y.^2 x y ones(size(x))]; % design matrix
S = D'*D; % scatter matrix
C(6,6)=0; C(1,3)=-2; C(2,2)=1; C(3,1)=-2; % constraints matrix
% solve the generalized eigensystem
[V,D] = eig(S, C);
% find the only negative eigenvalue
[n_r, n_c] = find(D<0 & ~isinf(D));
if isempty(n_c),
warning('Error getting the ellipse parameters, will do LS');
[Q,a] = fit_ellipse_ls(data); %
return;
end
% the parameters
a = V(:, n_c);
[A B C D E F] = deal(a(1),a(2),a(3),a(4),a(5),a(6)); % deal is slow!
Q = [A B/2 D/2; B/2 C E/2; D/2 E/2 F];
end % fit_ellipse_fitzgibbon
Run Code Online (Sandbox Code Playgroud)
不过,Fitzibbon 解具有一定的数值稳定性。请参阅 Halir 的工作来解决此问题。
它本质上是最小二乘解,但经过专门设计,可以生成有效的椭圆,而不仅仅是任何圆锥曲线。
| 归档时间: |
|
| 查看次数: |
2459 次 |
| 最近记录: |