我希望每帧的x和y帧坐标更新。但坐标没有这样做。它只获取第一帧的坐标。
编码是:
EyeDetect = vision.CascadeObjectDetector('EyePairBig');
vidD = imaq.VideoDevice('winvideo',1,'MJPG_640x480');
EFrame = step(vidD);
bboxe = step(EyeDetect, EFrame);
x = bboxe(1, 1); y = bboxe(1, 2); w = bboxe(1, 3); h = bboxe(1, 4);
bboxPolygon = [x, y, x+w, y, x+w, y+h, x, y+h];
textColor = [255, 0, 0];
textLocation = [1 1];
text = ['x: ',num2str(bboxe(1)),' y: ',num2str(bboxe(2))];
textInserter = vision.TextInserter(text,'Color', textColor, 'FontSize', 12, 'Location', textLocation);
vido = step(textInserter, EFrame);
EFrame = insertShape(vido, 'Polygon', bboxPolygon);
figure; imshow(EFrame); title('Eyes Detection');
% Detect feature points in the eye region.
points = detectMinEigenFeatures(rgb2gray(EFrame), 'ROI', bboxe);
% Display the detected points.
figure, imshow(EFrame), hold on, title('Detected features');
plot(points);
pointTracker = vision.PointTracker('MaxBidirectionalError', 2);
points = points.Location; initialize(pointTracker, points, EFrame);
videoPlayer = vision.VideoPlayer('Position',... [100 100 [size(EFrame, 2), size(EFrame, 1)]+30]);
oldPoints = points;
nFrames=0;
while (nFrames<100)
% get the next frame
EFrame = step(vidD);
% Track the points. Note that some points may be lost.
[points, isFound] = step(pointTracker, EFrame);
visiblePoints = points(isFound, :);
oldInliers = oldPoints(isFound, :);
if size(visiblePoints, 1) >= 2 % need at least 2 points
[xform, oldInliers, visiblePoints] = estimateGeometricTransform(...
oldInliers, visiblePoints, 'similarity', 'MaxDistance', 4);
[bboxPolygon(1:2:end), bboxPolygon(2:2:end)] ...
= transformPointsForward(xform, bboxPolygon(1:2:end), bboxPolygon(2:2:end));
EFrame = insertShape(EFrame, 'Polygon', bboxPolygon);
% Display tracked points
%EFrame = insertMarker(EFrame, visiblePoints, '+','Color', 'white');
% Reset the points
oldPoints = visiblePoints;
setPoints(pointTracker, oldPoints);
text = ['x: ',num2str(bboxe(1)),' y: ',num2str(bboxe(2))];
textInserter = vision.TextInserter(text,'Color', textColor, 'FontSize', 12, 'Location', textLocation);
end
% Display the annotated video frame using the video player object
EFrame= step(textInserter,EFrame);
step(videoPlayer, EFrame);
nFrames= nFrames+1;
end
release(vidD); release(videoPlayer); release(pointTracker);
答案 0 :(得分:0)
替换
行text = ['x: ',num2str(bboxe(1)),' y: ',num2str(bboxe(2))];
用这个:
text = ['x: ',num2str(bboxPolygon(1)),' y: ',num2str(bboxPolygon(2))];