finding points in a video

2 views (last 30 days)
C.G. on 11 May 2020
Commented: Image Analyst on 12 May 2020
I have a video of a series of footballs. I have plotted the centroids of each football in each frame, which has allowed me to work out translation.
I am trying to work out if it is possible to find another point on the footballs, for example the centre of the black pentagons, which will let me work out rotation.
Does anybody know if this is possible?
%Track the particles and plot velocity for t and t+1 (frames 1 + 2)
for loop = 1:numFrames;
%binarize frames 1 and 2 from the video (using rgb2gray)
frame_1 = rgb2gray(read(obj,loop+start_frame-1));
frame_2 = rgb2gray(read(obj,loop+start_frame));
%identify the circles in frames 1 and 2 with radii between the defined min and max
centres_1 =imfindcircles(frame_1,[min_radius,max_radius],'Sensitivity',quality,'Method','TwoStage');
centres_2 =imfindcircles(frame_2,[min_radius,max_radius],'Sensitivity',quality,'Method','TwoStage');
% dsearchm returns the indicies of the closest points in the 2 vectors
% identifies where each centroid has moved between frames 1 and 2
[index,dist] = dsearchn(centres_2,centres_1);
% here we have the distances not in order
% assign the centres from frames 1 and 2 to x and y coordinate variables
x_1{loop} = centres_1(:,1);
x_2{loop} = centres_2(index,1);
y_1{loop} = centres_1(:,2);
y_2{loop} = centres_2(index,2);
% now we compute the translational velocity as s = d/t
vel_x{loop} = (x_2{loop}-x_1{loop})/t; %x velocity using frame 2 - frame 1
vel_y{loop} = (y_2{loop}-y_1{loop})/t; %y velocity using frame 2 - frame 1
vel_res{loop} = sqrt(vel_x{loop}.^2 + vel_y{loop}.^2); %the final velocity vector as a function as its x and y components
% now we can make a overall velocity, by reshaping the array
% for all the columns in 'loop', reshape the array 'griddata' to define, size U, V and RES

Accepted Answer

Image Analyst
Image Analyst on 11 May 2020
Edited: Image Analyst on 11 May 2020
You can use regionprops() to find the centers of the black pentagons:
binaryImage = grayImage < someGrayLevel;
binaryImage = imclearborder(binaryImage); % Get rid of surrounding black stuff.
binaryImage = bwareafilt(binaryImage, [100, inf]); % Extract only blobs bigger than 100 pixels.
props = regionprops(binaryImage, 'Centroid', 'Area')
xy = vertcat(props.Centroid)
Adapt as needed.
See my Image Segmentation Tutorial for a full demo.
Image Analyst
Image Analyst on 12 May 2020
I don't know because I have never heard of or used the dsearchn() function, so you know more than me about it now.

Sign in to comment.

More Answers (0)


Community Treasure Hunt

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

Start Hunting!