Image Processing, Draw Line, Find Angle

11 vues (au cours des 30 derniers jours)
Teo Chou Wen
Teo Chou Wen le 2 Juin 2020
Commenté : Teo Chou Wen le 6 Juin 2020
Hi all, I currently doing a project to find the angle for the leg of a cyclist in video.
Below is the code and the output I able to get
video = VideoReader('BikeFit1.mp4');
nFrame = video.NumFrames;
for img = 1:nFrame;
frames = read(video,img);
imshow (frames); %Able to detect the red area but not able to run all the frames after detected
myVideo = VideoWriter ('AfterDetected.mp4'); %To create video
myVideo.FrameRate = 10; %To create video
open(myVideo) %To create video
%Filter the frames to detect the red marker
diff_im = imsubtract(frames(:,:,1), rgb2gray(frames));
diff_im = medfilt2(diff_im, [3 3]);
diff_im = imbinarize(diff_im,0.18);
diff_im = bwareafilt(diff_im,[1000 2200]);
bw = bwlabel(diff_im, 8);
stats = regionprops(bw, 'BoundingBox', 'Centroid');
%Mark the red marker
hold on
for object = 1:length(stats)
bb = stats(object).BoundingBox;
bc = stats(object).Centroid;
rectangle('Position',bb,'EdgeColor','r','LineWidth',2)
plot(bc(1),bc(2), '-m')
a=text(bc(1)+15,bc(2), strcat('X: ', num2str(round(bc(1))), ' Y: ', num2str(round(bc(2)))));
set(a, 'FontName', 'Arial', 'FontWeight', 'bold', 'FontSize', 12, 'Color', 'white');
end
hold off
pause(0.01) %To create video
frames2 = getframe(gcf); %To create video
writeVideo (myVideo,frames2); %To create video
close(myVideo) %To create video
end
** Now I need
  1. filter the unwanted red areas, only the three markers on leg is needed
  2. draw line between 2 markers (will have 2 lines)
  3. get the angle between 2 lines
  4. Save it in video, the code above with comment %to create video is not function.
But until now, I not able to find the suitable code to do these, may anyone help?
Thank you very much
  1 commentaire
Teo Chou Wen
Teo Chou Wen le 6 Juin 2020
Really needs help, thanks

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Convert Image Type dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by