tracking object in a video

5 ビュー (過去 30 日間)
Benjamin Lemoine
Benjamin Lemoine 2020 年 4 月 6 日
回答済み: darova 2020 年 4 月 6 日
Hello,
I have a video of someone who has an orange in his hand and my goal is to track this orange. First of all i have to create a ROI around this orange after the segmentation:
Left: the original video , Right: the video with segmentation to just have the orange.
Left: The ROI around the orange, Right: The virtual camera who follows the orange thanks to the ROI.
First of all i read the video and after, with a while, i must detect the orange in each frame:
videoFileReader = VideoReader('VT.mp4');;
VideoPlayer = vision.VideoPlayer('Position',[100,100,1920,1080]);
%% Detect oranges in each frame
while hasFrame(videoFileReader)
videoFrame = readFrame(videoFileReader);
Bin=videoFrame(:,:,1);
frame_binarise=imbinarize(Bin);
surface=sum(sum(frame_binarise));
[X_barycentre, Y_barycentre] = calcul_Barycentre(frame_binarise);
X=floor(X_barycentre);
Y=floor(Y_barycentre);
se = strel("diamond",1);
contour = frame_binarise - imerode(frame_binarise,se);
imshow(frame_binarise);
end
My baryencenter function:
function [X_barycentre, Y_barycentre] = calcul_Barycentre(img)
[LIG,COL]=size(img);
% Surface
S = sum(sum(img));
% X_barycentre
sumX = 0;
for l=1:1:COL
sumX = sumX+l*sum(img(:,l));
end
X_barycentre = sumX/S;
% Y_barycentre
sumY = 0;
for k=1:1:LIG
sumY = sumY+k*sum(img(k,:));
end
Y_barycentre = sumY/S;
So my probleme is how to make the ROI around the orange ?
  2 件のコメント
darova
darova 2020 年 4 月 6 日
You have center of the orange and want coordinates of rectangle? Is it correct?
Benjamin Lemoine
Benjamin Lemoine 2020 年 4 月 6 日
Yes i want to have a rectangle like the second photo at left

サインインしてコメントする。

採用された回答

darova
darova 2020 年 4 月 6 日
if these [X_barycentre, Y_barycentre] are coordinates of a center
Use imcrop to crop the image
h = 50; % side of rectangle
I1 = imcrop(videoFrame ,[X_barycentre-h/2 Y_barycenre-h/2 h h])

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTracking and Motion Estimation についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by