如何将活动轮廓添加到实时视频中的边界框

时间:2015-11-19 12:32:49

标签: matlab simulink matlab-cvst

这是使用“VIOLA AND JOHNES ALGORITHM'”开发的面部检测模型。和' CAMShift'。它使用边界框来跟踪和检测面部。我想添加活动轮廓/动态活动轮廓以获得实时视频中脸部的精确形状。它应该只捕捉脸部的轮廓而不是它的特征。如何在matlab中添加实时视频中的活动轮廓?

faceDetector = vision.CascadeObjectDetector();

%Get the input device using image acquisition toolbox,resolution = 640x480 to improve performance
obj =imaq.VideoDevice('winvideo', 1, 'YUY2_320x240','ROI', [1 1 320 240]);
set(obj,'ReturnedColorSpace', 'rgb');
figure('menubar','none','tag','webcam');

while (true)
    frame=step(obj);
    bbox=step(faceDetector,frame);

    boxInserter  = insertObjectAnnotation(frame,'rectangle',bbox, 'Face Detected');

    imshow(boxInserter,'border','tight');

    f=findobj('tag','webcam');

    if (isempty(f));
        [hueChannel,~,~] = rgb2hsv(frame);

% Display the Hue Channel data and draw the bounding box around the face.
figure, imshow(hueChannel), title('Hue channel data');

rectangle('Position',bbox,'EdgeColor','r','LineWidth',1, 'Face Detected')
hold off
noseDetector = vision.CascadeObjectDetector('Nose');
faceImage    = imcrop(frame,bbox);
imshow(faceImage)  
noseBBox     = step(noseDetector,faceImage);

noseBBox(1:1) = noseBBox(1:1) + bbox(1:1);
videoInfo    = info(obj);
ROI=get(obj,'ROI');
VideoSize = [ROI(3) ROI(4)];

videoPlayer  = vision.VideoPlayer('Position',[300 300 VideoSize+30]);
tracker = vision.HistogramBasedTracker;
initializeObject(tracker, hueChannel, bbox);

while (1)

% Extract the next video frame
    frame = step(obj);
% RGB -> HSV
    [hueChannel,~,~] = rgb2hsv(frame);

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

    % Insert a bounding box around the object being tracked

    %Insert text coordinates

    % Display the annotated video frame using the video player object
    step(videoPlayer);
    pause (.2)
end

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

        close(gcf)

        break
    end
    pause(0.05)
end
release(obj)

2 个答案:

答案 0 :(得分:1)

图像处理工具箱中有activecontour个功能。您可以裁剪包含面部的边界框,并尝试使用activecontour查找面部的确切形状。

答案 1 :(得分:0)

这是一种不同的方法,但它可能有助于根据面部标志获得精确的脸部形状。 http://cmp.felk.cvut.cz/~uricamic/clandmark/