指定した領域の重心を結んだ中点の検出方法
Ältere Kommentare anzeigen
以下のプログラムはPhotoshopで切り抜いた領域の重心を結んだ三角形を求め顔の向きを検出するプログラムです。
今回、教えて頂きたいのは目の領域の重心同士を結んだ中点(EyeMid)の検出方法です。
目の領域の指定方法等が分からずつまずいてしまいました。ご教授頂きたいです。

%% Photoshop画像読込
Icolor = imread('画像');
I = rgb2gray(Icolor); % グレースケール化
bgc = I(10,10); % 背景色の選択
%% 目と口の重心を求める
BW = I > bgc + 1 | I < bgc - 1; % (ほぼ)背景と背景以外で2値化(imbinarize)
s = regionprops(BW,'centroid'); % イメージ内の連結要素の重心を計算
Areas = regionprops(BW,'Area'); % 各重心位置計算されたエリアの面積
centroids = cat(1,s.Centroid); % 重心を格納する構造体配列を単一の行列に連結
centroids = centroids(cat(1,Areas.Area) > 10, :); % 面積の大きな連結要素のみ選択
%% 目と口の重心点を結んだ三角形の重心を求める
triangle = polyshape(centroids(:,1),centroids(:,2)); % 重心点を結んだ三角形を定義
[trcntx,trcnty] = centroid(triangle); % 三角形の重心
sorted = sort(centroids(:,1)); % 目と口の重心点(x座標)をソート
%% グラフィック表示
imshow(Icolor);
hold on;
plot(triangle);
plot(trcntx,trcnty,'*','Color','w');
if sorted(2) - trcntx < 0 %(口の重心点)-(三角形の重心点)<0 なら右向きと表示
text(trcntx-40,trcnty-350,'右向き','Color','w','FontSize',40);
elseif (-30 < sorted(2) - trcntx) && (sorted(2) - trcntx < 30)
text(trcntx-40,trcnty-350,'正面','Color','w','FontSize',40);
else
text(trcntx-40,trcnty-350,'左向き','Color','w','FontSize',40);
end
hold off;
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu オブジェクト解析 finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!