我正在使用 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);