2014-05-20 56 views
1

我有一個倒立擺視頻here,它的長度爲33秒。目標是在擺的移動矩形部分的中心繪製一個紅點,並繪製黑線上每條線的角度。使用MATLAB對視頻進行圖像檢測和跟蹤

我已經逐幀處理了視頻。然後我用Object Detection In A Cluttered Scene Using Point Feature Matching。如果我有權訪問匹配點的索引,然後輕鬆計算角度,那就太好了。

我以爲我可以得到移動矩形部分的區域,並尋找下一幀中的相似區域。但這個解決方案似乎太局部了。

我不知道應用哪種技術。

clear all; 
clc; 

hVideoFileReader = vision.VideoFileReader; 
hVideoPlayer = vision.VideoPlayer; 

hVideoFileReader.Filename = 'inverted-pendulum.avi'; 

hVideoFileReader.VideoOutputDataType = 'single'; 

while ~isDone(hVideoFileReader) 

    grayFrame = rgb2gray(step(hVideoFileReader)); 
    frame = step(hVideoFileReader); 

    if isFirstFrame 
     part = grayFrame(202:266,202:282); % #moving part's region 
     isFirstFrame = false; 
     subplot(1,2,1); 
     imshow(part); 
    end 

    partPoints = detectSURFFeatures(part); 
    grayFramePoints = detectSURFFeatures(grayFrame); 


    hold on; 
    subplot(1,2,1), plot(partPoints .selectStrongest(10));  
    subplot(1,2,2), imshow(grayFrame); 

    subplot(1,2,2), plot(grayFramePoints .selectStrongest(20)); 


    frame2 = pointPendulumCenter(frame); 

    frame3 = plotLineAlongStick(frame2); 

    step(hVideoPlayer, frame3); 


    hold off; 

end 

release(hVideoFileReader); 
release(hVideoPlayer); 


%% #Function to find the moving part's center point and plot a red dot on it. 
function f = pointPendulumCenter(frame) 
end 

%% #Function to plot a red line along the stick after calculating the angle of it. 
function f = plotLineAlongStick(frame) 
end 
+0

據我所見,您發佈的代碼只是讀取視頻並運行'findCenterofRectangle(frame)'和'plotLineAlongStick(frame)'。如果你可以在你展示的位置添加一個mcve(可能是兩張圖片),你會得到多少。您應該發佈這些功能的代碼。您提供的代碼不會增加太多價值。此外,添加一些人們可以使用的靜態圖像,在其中添加一些其他圖像。手工繪製以準確顯示您想要達到的效果。我認爲你需要縮小你的問題,因爲目前這個問題相當廣泛。 – kkuilla

回答

0

如果您的相機沒有移動,這會讓問題變得更容易。如果您使用固定相機拍攝視頻(例如,安裝在三腳架上),則可以使用vision.ForegroundDetector將靜止背景中的移動物體分割出來。

+0

相機不完全靜止。它移動一點點 – zkanoca

+0

在您發佈的視頻中,移動了很多... – Dima

+0

我嘗試過'vsion.ForegroundDetector'。它圍繞移動部分繪製白色矩形。但我不知道哪個矩形將被修改。我只需要在運動部件的中心繪製一個紅點,並沿着黑棒繪製一條紅線。我更新了我的代碼。也許你想看看。問候。 – zkanoca