M2soft |
۰۱-۱۲-۱۳۹۴ ۰۸:۰۴ بعد از ظهر |
PHP Code:
function [imgFace, LeftEye, RightEye, Mouth, LeftEyebrow, RightEyebrow] = detectFacialRegions(I) % This function is to find the facial regions (eyes, mouth and eyebrows) % Reference: % Silva, Caroline; Schnitman, Leizer ; Oliveira, Luciano. "Detection of Facial Landmarks % Using Local-Based Information". The 19th edition of the Brazilian Conference on Automation - CBA 2012, % Campina Grande, PB, Brazil (oral presentation), September 3, 2012. % % Copyright 2014 by Caroline Pacheco do E.Silva % If you have any problem, please feel free to contact Caroline Pacheco do E.Silva. % lolyne.pacheco@gmail.com %%
%To detect Face FDetect = vision.CascadeObjectDetector; Face = step(FDetect,I); imgFace = (I(Face(1,2):Face(1,2)+Face(1,4),Face(1,1):Face(1,1)+Face(1,3),:));
%To detect Left Eye EyeDetect = vision.CascadeObjectDetector('LeftEye'); Eye=step(EyeDetect,imgFace); LeftEye = Eye(1,:); %To detect Right Eye EyeDetect = vision.CascadeObjectDetector('RightEye'); Eye=step(EyeDetect,imgFace); RightEye = Eye(2,:); %To detect Mouth MouthDetect = vision.CascadeObjectDetector('Mouth','MergeThreshold',16); findMouth=step(MouthDetect,imgFace); orderMouth= sortrows(findMouth,2); posMouth = size(findMouth,1); Mouth = orderMouth(posMouth,:);
%To detect Left Eyebrow LeftEyebrow = LeftEye; LeftEyebrow(4) = (LeftEyebrow(4)/2)-4; LeftEyebrow(3) = LeftEyebrow(3); LeftEyebrow(4) = uint8(LeftEyebrow(4)); LeftEyebrow(3) = uint8(LeftEyebrow(3));
%To detect Right Eyebrow RightEyebrow = RightEye; RightEyebrow(4) = (RightEyebrow(4)/2); RightEyebrow(3) = RightEyebrow(3); RightEyebrow(4) = uint8(RightEyebrow(4)); RightEyebrow(3) = uint8(RightEyebrow(3));
end
کد بالا یک تابع است که یک عکس به عنوان ورودی میپذیره و با استفاده از object ویلاجوینز ( viola jones ) میادویژگی های اونو استخراج میکنه
مثل صورت
چشم ها
ابروها
دهان
این تیکه کد زیر هم میاد بعد از تشخیص صورت اون و از تصویر جدا میکنه و خودش میشه یه عکس کوچولو از ناحیه صورت
PHP Code:
FDetect = vision.CascadeObjectDetector; Face = step(FDetect,I); imgFace = (I(Face(1,2):Face(1,2)+Face(1,4),Face(1,1):Face(1,1)+Face(1,3),:));
البته این فقط برای عکسهایی است که یک چهره در اون هست
یعنی ایندکس 1 در face(1,?) به همین جهت استفاده شده
چون وقتی کد step(FDetect,I) و اجرا میکنیم به ما یک ارایه 1 تا n سطری برمیگردونه که هر سطرش 4 تا مقدار داره که همون 4 نقطه چهره است و تعداد سطرها هم تعداد چهره های شناسایی شده
که البته یعضی وقت ها یک سری چهره ها الکی تشخیص داده میشه
یعنی همیشه ما چهره های شناسایی شده و نمیتونیم ازش مطمئن حرف بزنیم
تو تصویر هم همیشه شاید چشم راست یا همیشه چشم چپ نداشته باشیم
این کد هم از اون تابع استفاده کردم
PHP Code:
clear all; close all; clc
I = imread('1.jpg'); [imgFace, LeftEye, RightEye, Mouth, LeftEyebrow, RightEyebrow] = detectFacialRegions(I);
figure,imshow(imgFace);
hold on rectangle('Position',LeftEye(1,:),'LineWidth',1,'LineStyle','-','EdgeColor','b'); rectangle('Position',RightEye(1,:),'LineWidth',1,'LineStyle','-','EdgeColor','g'); %rectangle('Position',Mouth(1,:),'LineWidth',1,'LineStyle','-','EdgeColor','b'); %rectangle('Position',LeftEyebrow(1,:),'LineWidth',1,'LineStyle','-','EdgeColor','y'); %rectangle('Position',RightEyebrow(1,:),'LineWidth',1,'LineStyle','-','EdgeColor','r'); hold off
|