I have calculated the distance between fixed object and moving object in a video. Using this distance I am trying to calculate the displacement of moving object in consecutive frame.
2 ビュー (過去 30 日間)
古いコメントを表示
I have tried doing it, but I am getting error.
if true
% code
end X(r)=thisCentroid(:,1);
Y(r)=thisCentroid(:,2);
if r>=2
dx=X(2)-X(1);
dy=Y(2)-Y(1);
dist_c(k)=hypot(dx,dy);
save dist_c dist_c;
for k=2:numberOfFrames
q(k)=imsubtract(dist_c(k),dist_c(k-1));
end
The error which I am getting while running the code is
- Attempted to access dist_c(2); index out of bounds because numel(dist_c)=1 .
Error in Untitled2 (line 92)
*q(k)=imsubtract(dist_c(k),dist_c(k-1));*
*
0 件のコメント
回答 (1 件)
sandeep
2014 年 11 月 20 日
Try using pdist() function to calculate the distance between two points and save it to an array. It is not clear in the code about k value from the loop. It looks your dist_c has only one value and you are trying access from the second value.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!