2013-10-20 2 views
1

MATLAB을 사용하여 실시간 얼굴 검출기를 만들려고합니다. Mathworks '페이지에서 샘플 코드를 찾았지만 샘플 비디오를 사용합니다. 이 코드는 오프닝 프레임에서 몇 개의 면만 선택해도 추적 할 수있는 문제점이 있습니다. 한 번에 여러 얼굴을 추적해야합니다. 과감하지 않은이 코드의 변경으로 가능합니까? 나는 매스 웍스의 웹 페이지에 다음 코드를 발견MATLAB의 실시간 얼굴 검출

% Create a cascade detector object. 
faceDetector = vision.CascadeObjectDetector(); 

% Read a video frame and run the detector. 
videoFileReader = vision.VideoFileReader('visionface.avi'); 
videoFrame  = step(videoFileReader); 
bbox   = step(faceDetector, videoFrame); 

% Draw the returned bounding box around the detected face. 
videoOut = insertObjectAnnotation(videoFrame,'rectangle',bbox,'Face'); 
figure, imshow(videoOut), title('Detected face'); 

% Get the skin tone information by extracting the Hue from the video frame 
% converted to the HSV color space. 
[hueChannel,~,~] = rgb2hsv(videoFrame); 

% Display the Hue Channel data and draw the bounding box around the face. 
figure, imshow(hueChannel), title('Hue channel data'); 
rectangle('Position',bbox(1,:),'LineWidth',2,'EdgeColor',[1 1 0]) 

% Detect the nose within the face region. The nose provides a more accurate 
% measure of the skin tone because it does not contain any background 
% pixels. 
noseDetector = vision.CascadeObjectDetector('Nose'); 
faceImage = imcrop(videoFrame,bbox(1,:)); 
noseBBox  = step(noseDetector,faceImage); 

% The nose bounding box is defined relative to the cropped face image. 
% Adjust the nose bounding box so that it is relative to the original video 
% frame. 
noseBBox(1,1:2) = noseBBox(1,1:2) + bbox(1,1:2); 

% Create a tracker object. 
tracker = vision.HistogramBasedTracker; 

% Initialize the tracker histogram using the Hue channel pixels from the 
% nose. 
initializeObject(tracker, hueChannel, noseBBox(1,:)); 

% Create a video player object for displaying video frames. 
videoInfo = info(videoFileReader); 
videoPlayer = vision.VideoPlayer('Position',[300 300 videoInfo.VideoSize+30]); 

% Track the face over successive video frames until the video is finished. 
while ~isDone(videoFileReader) 

% Extract the next video frame 
videoFrame = step(videoFileReader); 

% RGB -> HSV 
[hueChannel,~,~] = rgb2hsv(videoFrame); 

% Track using the Hue channel data 
bbox = step(tracker, hueChannel); 

% Insert a bounding box around the object being tracked 
videoOut = insertObjectAnnotation(videoFrame,'rectangle',bbox,'Face'); 

% Display the annotated video frame using the video player object 
step(videoPlayer, videoOut); 

end 

% Release resources 
release(videoFileReader); 
release(videoPlayer); 

사전에 감사!

답변

2

이 예는 단일 얼굴 만 추적하도록 설계되었습니다. 여러 객체를 추적하려면 추적을 위해 vision.KalmanFilter 객체를 사용하는 example을 살펴보십시오. 이 예제의 탐지 부분을면을 탐지하는 코드로 바꿀 수 있습니다.

또는 example that uses the KLT algorithm (vision.PointTracker)을보고 추적 지점을 확인하십시오. 여러면을 추적하도록 수정할 수는 있지만 훨씬 더 많은 작업이 필요합니다. 어떤 점이 어느 얼굴에 속해 있는지 추적하려면 많은 부기 관리를해야합니다.

편집 : 여기 여러 얼굴을 추적하는 vision.PointTracker을 사용하는 방법에 대한 example입니다.