0

顔の特徴抽出に関するプロジェクトを行っています。ヒストグラムの均等化、顔の検出、および顔のトリミングのための MATLAB コードを作成しました。顔が傾いている場合は、顔をまっすぐにしたいです。MATLAB コードについて教えてください。これまでに書いたコードは次のとおりです。

clear all
clc

I=imread('100_3082.jpg');
figure(1)
imshow(I);
J=rgb2gray(I);
figure(2)
imshow(J);                                                             
P = histeq(J);
figure(3)
imshow(P);

FDetect = vision.CascadeObjectDetector;

BB = step(FDetect,P);
hold on
for i = 1:size(BB,1)
rectangle('Position',BB(i,:),'LineWidth',5,'LineStyle','-','EdgeColor','r');

end
for i = 1:size(BB,1)
Q= imcrop(P,BB(i,:));
figure(4)
imshow(Q);
end
title('Face Detection');   

hold off;

これは私が取り組んでいる画像 ( 「100_3082.jpg」 ) です:-

100_3082.jpg

4

1 に答える 1

3

アルゴリズム:-
私のソリューションは、次のアルゴリズムを使用してタスクを実装します。

1.両目の位置を見つける。
2.それらの間の角度を見つける。
3.その角度に基づいて画像を回転します。

入力画像:-
このコードの入力画像は、コードの最後に取得するものですQ

入力

コード:-

% Dividing the image in two halves for better detection
% To see why , see this: https://www.mathworks.com/matlabcentral/answers/155126-how-does-the-vision-cascadeobjectdetector-detect-left-and-right-eyes-separately-it-is-constantly-de
n = fix(size(Q,2)/2);
lefthalf = Q(:,1:n,:);
righthalf = Q(:,n+1:end,:);

RightEyeDetect = vision.CascadeObjectDetector('RightEyeCART');
LeftEyeDetect = vision.CascadeObjectDetector('LeftEyeCART');
% vision.CascadeObjectDetector(EyePairBig) is not much efficient in this case
% because the image is tilted. So, detecting both eyes separately.

%Bounding Boxes
BBREye= step(RightEyeDetect,lefthalf); %Right eye is on our left
BBLEye= step(LeftEyeDetect,righthalf); %Left eye is on our right
BBLEye(1)=BBLEye(1)+n; %correcting the x position of left eye (caused due to dividing the image in two halves)

figure
imshow(imrotate(Q,(180/pi)*atan((BBREye(2)-BBLEye(2))/(BBREye(1)-BBLEye(1)))));

出力:-

出力


PS:
1.これは完璧な解決策ではないかもしれません。
2.補正する傾斜面は 1 つだけであると仮定します。
3.このソリューションの精度は、 Viola-Jones Algorithmに基づく組み込みの MATLAB 関数が使用される目の検出の精度に依存します。
4.このコードが失敗した場合は、次の行を追加して目が正しく検出されたかどうかを確認できます。

BBEyes= [BBLEye ; BBREye];
figure,
imshow(Q); 
for i = 1:size(BBEyes,1)
 rectangle('Position',BBEyes(i,:),'LineWidth',4,'LineStyle','-','EdgeColor','r');
end

画像については、これが機能したため、目が正しく検出されたかどうかを確認できます。結果は次のとおりです。これは正しいです:-

目の検出

于 2016-09-04T07:35:58.710 に答える