The function below will calculate the tendency points of two ellipses including the cross points and the tangency points. I have two pictures which I have to retrieve the vanishing points from two ellipses plane of the car. The function works well for the first image but for the second image it gives me the wrong coordinates for the cross points and tangency points of the front wheel.
This is the function:
function points = ellipsesPointsSelection( C1, H1, C2, H2)
% this function takes into account two ellipses matrices and the
% homographies to apply to them (rotation translation) and returns
% the four tangency points of the two bitangent lines to the two ellipses
syms l1 l2
l = [l1; l2; 1];
eqns = [l.'*inv(inv(H1).'*C1*inv(H1))*l == 0, l.'*inv(inv(H2).'*C2*inv(H2))*l == 0];
vars = [l1 l2];
[sol_l1, sol_l2] = vpasolve(eqns, vars);
L = [double(sol_l1.'); double(sol_l2.'); ones(1,4)];
X = (inv(H1).'*C1*inv(H1))\L;
Y = (inv(H2).'*C2*inv(H2))\L;
pt_tng_ul = X(:,1)'; % upper (u) point (pt) tangent (tng) to the left (l) ellipse
pt_tng_ur = Y(:,1)';
pt_tng_dr = Y(:,2)';
pt_tng_dl = X(:,2)';
pt_cross_ul = X(:,4)'; % upper (u) point (pt) tangent (tng) to the left (l) ellipse
pt_cross_dl = X(:,3)';
pt_cross_dr = Y(:,4)';
pt_cross_ur = Y(:,3)';
points = [ pt_tng_ul;
pt_tng_ur;
pt_tng_dr;
pt_tng_dl;
pt_cross_ul;
pt_cross_ur;
pt_cross_dr;
pt_cross_dl];
end
I'm using the function like this in my main code:
norm_matrix = diag([1, 1, 1]);% normalization off
H1 = norm_matrix*H1; % normalized rototranslation
H2 = norm_matrix*H2; % normalized rototranslation
ellipsesPoints = ellipsesPointsSelection(C1, H1, C2, H2);
H1_1 = norm_matrix*H1_1; % normalized rototranslation
H2_2 = norm_matrix*H2_2; % normalized rototranslation
ellipsesPoints2 = ellipsesPointsSelection(C1_1, H1_1, C2_2, H2_2);
and the result for image1 is:
and the result for the second image tangency points is this one:
As you can see the tangency points for the front wheel are not correct. I tried to fix another ellipse for the front wheel of the second image and the parameters of C and H changed a little bit but still, tangency points are wrong. I appreciate your comments and opinions regarding this problem.
CodePudding user response:
The ellipse detection technique is simply detecting the best fit ellipse by receiving the semi-major and semi-minor axis of the ellipses. and return and ellipse which:
x_c_1 = ellipse1_Front(1,1); % x position of the center of the image1 front wheel
y_c_1 = ellipse1_Front(1,2); % y position of the center of the image1 front wheel
semi_maj_1 = ellipse1_Front(1,3); % semi major axis of the image1 front wheel
semi_min_1 = ellipse1_Front(1,4); % semi minor axis of the image1 front wheel
theta1 = ellipse1_Front(1,5)*pi/180; % angle of the image1 front wheel
in my case, the fifth element of the ellipse which is the theta1 was problematic for the ellipsePointsSelection function. i tried to change the input parameter for ellipseDetection function it means changing the semi-major and semi-minor values and found a suitable ellipse which also has tangency points aligned on it: enter image description here