what is wrong wit my code for tracking in real time

1 view (last 30 days)
% Webcam input delete(imaqfind)
vid=videoinput('winvideo',1,'YUY2_160x120');%YUY2_160x120 ,%RGB24_320x240
triggerconfig(vid,'manual');
set(vid,'FramesPerTrigger',1 );
set(vid,'TriggerRepeat', Inf);
set(vid,'ReturnedColorSpace','rgb');
start(vid) trigger(vid); I =getdata(vid,1); % Get the frame in im %% % Set variable for face detection face_detector = 0;
% Create a cascade detector object. faceDetector = vision.CascadeObjectDetector();
% Create a tracker object. tracker = vision.HistogramBasedTracker;
for ii = 1:1000 trigger(vid); I =getdata(vid,1); % Get the frame in im
subplot(2,3,[1 2 4 5])
imshow(I);
% If face is not detected then detect the face3
if face_detector==0
% Detect the face
bboxf = step(faceDetector, I);
if isempty(bboxf) % If face is not detected then continue
continue;
end
bboxf = bboxf(1,:);
rectangle('position',bboxf,'edgecolor','r','linewidth',3)
disp('Face detected');
% Create a small bounding box to detect only face
bbox = [bboxf(1)+bboxf(3)/4 bboxf(2)+bboxf(4)/4 bboxf(3)/2 bboxf(4)/2];
bbox = round(bbox);
rectangle('position',bbox,'edgecolor','y','linewidth',3)
% Make flag to 1 so that it will not detect the face in next
% frame
face_detector = 1;
% Get the skin tone information by extracting the Hue from the video frame
% converted to the HSV color space.
[hueChannel,~,~] = rgb2hsv(I);
% Initialize the tracker histogram using the Hue channel pixels from the
% nose.
initializeObject(tracker, hueChannel, bbox);
else
% Get the skin tone information by extracting the Hue from the video frame
% converted to the HSV color space.
[hueChannel,~,~] = rgb2hsv(I);
% Track using the Hue channel data
bbox = step(tracker, hueChannel);
if min(bbox(3),bbox(4))<30
face_detector=0;
pause(1)
continue;
end
text(bbox(1),bbox(2)+5,I,'color','y','fontsize',10,'fontweight','bold')
rectangle('position',bbox,'edgecolor','r')
end
  1 Comment
Jan
Jan on 4 Jul 2013
You forgot to explain any details about why you are assuming, that abnything is wrong. Please append useful explanations by editing the question (not as answer or comment). Otherwise we could only guess what you want to be changed.

Sign in to comment.

Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!