使用Matlab的视觉功能重新建立新的特征点

时间:2014-12-09 05:04:36

标签: matlab computer-vision matlab-cvst feature-tracking

我正在使用Matlab内置的视觉功能和预先制作的示例代码来跟踪特征点。在我的示例视频中,摄像机横向平移,向视野引入新物体和风景,而之前的物体和风景移出视野。

当摄像机在场景中平移时,尝试识别新的特征点时出现问题。我在视频步骤while循环中使用“detectMinEigenFeatures”功能,以便在步进指定数量的帧之后找到新的特征点。但是,这样做对于重新建立新的特征点没有任何作用。

一些快速信息:使用GoPro视频,采样到720p并保存为.avi

代码发布在下面,我很乐意提供更多可能有助于理解或解决此问题的信息。

谢谢!

clc;clear all;close all;

videoFileReader = vision.VideoFileReader('GoProFlyingMidFlightResized.avi');

videoFrame = step(videoFileReader);

%Create Video writer
TrackingVideo = VideoWriter('TrackingVideo.avi');

open(TrackingVideo);

% Detect feature points
points = detectMinEigenFeatures(rgb2gray(videoFrame),'MinQuality',0.04,'FilterSize',3);
% points = detectMinEigenFeatures(rgb2gray(videoFrame));

% Create a point tracker
pointTracker = vision.PointTracker('NumPyramidLevels',7,'MaxBidirectionalError', 8, 'MaxIterations',70,'BlockSize',[5 5]);

% Initialize the tracker with the initial point locations and the initial
% video frame.
points = points.Location;
initialize(pointTracker, points, videoFrame);

videoPlayer  = vision.VideoPlayer('Position',[100 100 [size(videoFrame, 2), size(videoFrame, 1)]+30]);

% Make a copy of the points for transformation between the consecutive feature points
oldPoints = points;
FrameCount=0; %For identifying that new feature points must be obtain

while ~isDone(videoFileReader)
    % get the next frame
    FrameCount=FrameCount+1;
    videoFrame = step(videoFileReader);

    if FrameCount==30  %If 30 frame have stepped though, find new feature points
        disp('help')
        points = detectMinEigenFeatures(rgb2gray(videoFrame),'MinQuality',0.04,'FilterSize',3);
        points = points.Location;
        FrameCount=0;
    end

    % Track the points.
    [points, isFound] = step(pointTracker, videoFrame);
    visiblePoints = points(isFound, :);
    oldInliers = oldPoints(isFound, :);

    if size(visiblePoints, 1) >= 2 % need at least 2 points

        % Estimate the geometric transformation between the old points
        % and the new points and eliminate outliers
        [xform, oldInliers, visiblePoints] = estimateGeometricTransform(oldInliers,   visiblePoints, 'similarity', 'MaxDistance', 10);

        % Display tracked points
        videoFrame = insertMarker(videoFrame, visiblePoints, '+','Color', 'red');

        % Reset the points
        oldPoints = visiblePoints;
        setPoints(pointTracker, oldPoints);
    end

    % Display video frame using the video player
    writeVideo(TrackingVideo,videoFrame);
    step(videoPlayer, videoFrame);
end

% Clean up
release(videoFileReader);
release(videoPlayer);
release(pointTracker);
close(TrackingVideo);

1 个答案:

答案 0 :(得分:1)

在if语句中,您检测到新点:

    if FrameCount==30  %If 30 frame have stepped though, find new feature points
        disp('help')
        points = detectMinEigenFeatures(rgb2gray(videoFrame),'MinQuality',0.04,'FilterSize',3);
        points = points.Location;
        FrameCount=0;
    end

现在,在同一个if内,你必须告诉点跟踪器这些新点:

setPoints(tracker, points);

否则,您的变量points会被下一行覆盖:

[points, isFound] = step(pointTracker, videoFrame);

这就是为什么你永远不会看到新检测到的点。