Image Processing, Draw Line, Find Angle

12 visualizaciones (últimos 30 días)
Teo Chou Wen
Teo Chou Wen el 2 de Jun. de 2020
Comentada: Teo Chou Wen el 6 de Jun. de 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

Respuestas (0)

Categorías

Más información sobre Convert Image Type en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by