Filter löschen
Filter löschen

hi .i'm new in matlab,plz how can i rotate all face images to be aligned vertically with same angle?

1 Ansicht (letzte 30 Tage)
i followed this procedure: detecting the eyes then computing both eye centers and getting the image center,lastly get the angle between three points ,plz,could you tell me the wrong with this code as it doesn't give the appropirate angle
if true
% code
%%To detect the Eyes
EyeDetect = vision.CascadeObjectDetector('EyePairBig');
%Read the input Image
I = imread('a7.jpg');
A=rgb2gray(imread('a7.jpg'));
center=size(A)/2+.5;
x0 = center(1:2:end);
y0= center(2:2:end);
BB=step(EyeDetect,I);
figure,imshow(I);
rectangle('Position',BB,'LineWidth',4,'LineStyle','-','EdgeColor','b');
title('Eyes Detection');
Eyes=imcrop(I,BB);
figure,imshow(Eyes)
[a b c]=size(Eyes);
I1=Eyes(:,1:b/2);
figure,imshow(I1)
[Label,Total]=bwlabel(I1,8);
num=1;
Sdata=regionprops(Label,'centroid');
[x]= Sdata(num).Centroid;
centroids = [Sdata.Centroid];
x1= centroids(1:2:end);
y1 = centroids(2:2:end);
I2=Eyes(:,b/2:b);
[Label2,Total2]=bwlabel(I2,8);
num=1;
Sdata=regionprops(Label2,'centroid');
[y]=Sdata(num).Centroid;
centroids = [Sdata.Centroid];
x2= centroids(1:2:end);
y2 = centroids(2:2:end);
z=[x;y];
P0 = [x0, y0];
P1 = [x1, y1];
P2 = [x2, y2];
n1 = (P2 - P0) / norm(P2 -P0); % Normalized vectors
n2 = (P1 - P0) / norm(P1 - P0);
theta = atan2(norm(det([n2; n1])), dot(n1, n2));
D = rad2deg(theta );
I=imrotate(Eyes,theta);
figure,imshow(I)

Antworten (1)

Image Analyst
Image Analyst am 15 Dez. 2017
Then, inside the loop, you might want to call imwrite() if you want to save the rotated images to disk.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by