【问题标题】:How to update the ( x,y ) coordinate for each frame?如何更新每一帧的 (x,y) 坐标?
【发布时间】:2014-03-11 11:29:51
【问题描述】:

我想要每帧更新 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);

【问题讨论】:

  • xy 是指bboxe 之外的值吗?由于您只创建一次(在 while 循环之外),并且永远不会更新它,因此这些值永远不会改变。
  • 是 bboxe 的值。我确实放了: text = ['x: ',num2str(bboxe(1)),' y: ',num2str(bboxe(2))]; textInserter = vision.TextInserter(text,'Color', textColor, 'FontSize', 12, 'Location', textLocation); vido = step(textInserter, EFrame);在while循环中,但它仍然没有改变..
  • 这些都不会改变bboxe 本身的内容,不是吗?
  • 是的,实际上我从这里得到了一些参考 [danielconde9spot.blogspot.com/2013_03_01_archive.html].. 但这里的跟踪使用直方图跟踪器。我尝试将坐标代码与我的结合起来,但似乎不太顺利

标签: matlab real-time tracking matlab-cvst


【解决方案1】:

换行

text =  ['x: ',num2str(bboxe(1)),' y: ',num2str(bboxe(2))];

用这个:

text =  ['x: ',num2str(bboxPolygon(1)),' y: ',num2str(bboxPolygon(2))];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-14
    • 1970-01-01
    • 2012-07-22
    • 2011-10-01
    • 2013-05-05
    相关资源
    最近更新 更多