finding points in a video

5 views (last 30 days)
C.G.
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
U(:,:,loop)=reshape(griddata(x_1{loop},y_1{loop},vel_x{loop},X(:),Y(:)),size(X,1),size(X,2));
V(:,:,loop)=reshape(griddata(x_1{loop},y_1{loop},vel_y{loop},X(:),Y(:)),size(X,1),size(X,2));
RES(:,:,loop)=reshape(griddata(x_1{loop},y_1{loop},vel_res{loop},X(:),Y(:)),size(X,1),size(X,2));
end

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.
  3 Comments
C.G.
C.G. on 12 May 2020
Could I ask a follow up question?
I have identified the centroids of the pentagons in 2 consectuive frames of my video, and I now want to use dsearchn to compute the difference.
However, when I have gone through the process for both frames, props returns 2 structures of different lengths, which means dsearchn comes up with the error below.
Is there a way of ensuring that the structures are the same length?
Error using dsearchn (line 65)
X and XI should have the same column dimension.
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)

Tags

Community Treasure Hunt

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

Start Hunting!