使用 Matlab 的视觉函数重新建立新的特征点

Posted

技术标签:

【中文标题】使用 Matlab 的视觉函数重新建立新的特征点【英文标题】:Re-establishing new feature points using Matlab's vision functions 【发布时间】:2014-12-09 05:04:35 【问题描述】:

我正在使用 Matlab 的内置视觉函数和预制示例代码来跟踪特征点。在我的示例视频中,相机水平平移,将新的物体和风景引入视野,而之前的物体和风景移出视野。

我的问题是在相机平移场景时尝试识别新特征点时出现的。我在 video-step 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】:

在 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);

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

【讨论】:

感谢 Dima,这确实是问题所在。感谢您的帮助! 不客气。我很好奇,对于点跟踪器的'MaxBidirectionalError' 参数,8 是一个合理的值吗?你这样不会得到很多坏道吗? 确实我做到了,但这只是为了测试目的,让自己对这个特定视频的属性敏感度有一个很好的了解。我使用 2 进行实际测试。

以上是关于使用 Matlab 的视觉函数重新建立新的特征点的主要内容,如果未能解决你的问题,请参考以下文章

用于转换特征提取函数的 Matlab 编码器

matlab opencv 特征点提取与匹配问题

MATLAB中的struct操作

图像特征分析:颜色特征描述,颜色矩,颜色直方图(附matlab代码)

matlab中怎么定义结构体

matlab中怎么定义结构体