Image Processing, Draw Line, Find Angle
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
- filter the unwanted red areas, only the three markers on leg is needed
- draw line between 2 markers (will have 2 lines)
- get the angle between 2 lines
- 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
Réponses (0)
Voir également
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!