Demo entry 2351106

dene

   

Submitted by anonymous on Aug 06, 2015 at 00:21
Language: Matlab. Code size: 4.4 kB.

function facelive()
%%
upperBDetector = vision.CascadeObjectDetector('UpperBody','MergeThreshold',8);
faceDetector = vision.CascadeObjectDetector('FrontalFaceLBP','MergeThreshold',8);
noseDetector = vision.CascadeObjectDetector('Nose','MergeThreshold',8);
eyeDetector = vision.CascadeObjectDetector('EyePairSmall','MergeThreshold',8);
mouthDetector = vision.CascadeObjectDetector('Mouth','MergeThreshold',8);
profileDetector = vision.CascadeObjectDetector('ProfileFace');
cam = webcam;
videoPlayer  = vision.VideoPlayer;
% Track the face over successive video frames until the video is finished.
pt=1;
SCORE=0.0;
Nhisbin=50;
while true
    pause(0.04);
    % Extract the next video frame
    videoFrame=snapshot(cam);
    % RGB -> HSV
    videoFrameGray=rgb2gray(videoFrame);
    [hueC,satC,valC] = rgb2hsv(videoFrame);
    oynan=zeros(480,640);
    oynan(find(hueC>0.6))=satC(find(hueC>0.6));
    trackFrame=;
    if SCORE<0.4
        bbox= step(faceDetector, videoFrame);
        if isempty(bbox)
           bbox= step(upperBDetector, videoFrame);
        end
        if ~isempty(bbox)
            videoOut = insertObjectAnnotation(videoFrame,'rectangle',bbox,'Face');
            for bboxcount=1:size(bbox,1)
            faceImage    = imcrop(videoFrame,bbox(bboxcount,:));
            noseBBox     = step(noseDetector,faceImage);
            if ~isempty(noseBBox)
                % Insert a bounding box around the object being tracked
                eyeBBox     = step(eyeDetector,faceImage);
                noseBBox(1,1:2) = noseBBox(1,1:2) + bbox(bboxcount,1:2);
                videoOut = insertObjectAnnotation(videoOut,'rectangle',noseBBox(1,:),'Nose');
                tracker = vision.HistogramBasedTracker;
%                 tracker = vision.PointTracker;
                if ~isempty(eyeBBox)
                    mouthArea=[bbox(bboxcount,1) bbox(bboxcount,2)+bbox(bboxcount,4)/2 bbox(bboxcount,3) bbox(bboxcount,4)/2];
                    mouthImage    = imcrop(videoFrame,mouthArea);
                    mouthBBox     = step(mouthDetector,mouthImage);
                        eyeBBox(1,1:2) = eyeBBox(1,1:2) + bbox(bboxcount,1:2);
                    videoOut = insertObjectAnnotation(videoOut,'rectangle',eyeBBox(1,:),'Eye');
                    if ~isempty(mouthBBox)
                            mouthBBox(1,1:2) = mouthBBox(1,1:2) + mouthArea(1,1:2);
                        videoOut = insertObjectAnnotation(videoOut,'rectangle',mouthBBox(1,:),'Mouth');
                        initializeObject(tracker, trackFrame, noseBBox(1,:),Nhisbin);
%                         points = detectMinEigenFeatures(videoFrame ,'ROI',eyeBBox(1,:));
%                         initialize(tracker,points.Location,trackFrame);
                    else                        
                        initializeObject(tracker, trackFrame, noseBBox(1,:),Nhisbin);
%                         points = detectMinEigenFeatures(videoFrame ,'ROI',eyeBBox(1,:));
%                         initialize(tracker,points.Location,trackFrame);
                    end
                else
                    initializeObject(tracker, trackFrame, noseBBox(1,:),Nhisbin);
%                     points = detectMinEigenFeatures(videoFrame ,'ROI',noseBBox(1,:));
%                     initialize(tracker,points.Location,trackFrame);
                end
                SCORE=1.0;
                
            end
            end
        else
           profileBBox= step(profileDetector, videoFrame);
           if ~isempty(profileBBox)
               videoOut = insertObjectAnnotation(videoFrame,'rectangle',profileBBox,'profileFace');
           else
               videoOut = videoFrame;
           end
        end
    else
        % Track using the Hue channel data
        [bbox,ORIENTATION, SCORE] = step(tracker, trackFrame);
%         [POINTS,POINT_VALIDITY,SCORES] = step(tracker,trackFrame);
%         Gpoints=POINTS(find(POINT_VALIDITY>0.999),:);
        % Insert a bounding box around the object being tracked
        videoOut = insertObjectAnnotation(videoFrame,'rectangle',bbox,num2str(SCORE));
%         videoOut = insertMarker(videoFrame, Gpoints, '+', 'Color', 'white');
    end
    % Display the annotated video frame using the video player object
    step(videoPlayer, videoOut);
    pt=pt+1;
end

% Release resources
release(videoPlayer);
clear all
end

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).