how to draw lines using given points in a video?

First,I give some points to starting posistion of the video,I need to draw lines through that points and get angles using x,y values,
Currently i able add points and get x,y values of those points while video playing.
videoFileReader = vision.VideoFileReader('ex.mp4');
videoPlayer = vision.VideoPlayer('Position',[1,10,1280,720]);
objectFrame = videoFileReader();
objectRegion = [264,122,93,93];
figure;
imshow(objectFrame);
[shoulder_X,shoulder_Y]= ginput(1);
[elbow_x,elbow_y]= ginput(1);
[wrist_x,wrist_y]= ginput(1);
pos = [shoulder_X,shoulder_Y;elbow_x,elbow_y;wrist_x,wrist_y];
color = {'red','green','magenta'};
start_x = shoulder_X;
start_y=shoulder_Y;
disp(shoulder_X +" - "+shoulder_Y);
% imshow(pointImage);
points = detectMinEigenFeatures(rgb2gray(objectFrame));
pointImage1 = insertMarker(objectFrame,pos,'+','Color',color,'size',10);
plot([shoulder_X,shoulder_Y], [elbow_x,elbow_y]);
plot([wrist_x,wrist_y], [elbow_x,elbow_y]);
figure;
imshow(pointImage1);
title('Detected interest points');
tracker = vision.PointTracker('MaxBidirectionalError',1);
initialize(tracker,pos,objectFrame);
while ~isDone(videoFileReader)
frame = videoFileReader();
[points,validity] = tracker(frame);
out = insertMarker(frame,points(validity, :),'+');
videoPlayer(out);
disp(points);
end
Capturesd.PNG
As shown in above image,
Black circle: current status of my code,and these points move when video playing,
Red Circle:I need to improve red circle to this level.and these lines should move when video playing.
I try to draw lines using plot function but its not work.
plot([shoulder_X,shoulder_Y], [elbow_x,elbow_y]);
plot([wrist_x,wrist_y], [elbow_x,elbow_y]);

2 Comments

try
plot([shoulder_X elbow_x wrist_x shoulder_X], ...
[shoulder_Y elbow_y wrist_y shoulder_Y])

Sign in to comment.

 Accepted Answer

Use insertShape(). Cool project!

10 Comments

I tried with this and not able to work with the video.It's draw lines in images.Where should i insert this method in my code?
tracker = vision.PointTracker('MaxBidirectionalError',1);
initialize(tracker,pos,objectFrame);
while ~isDone(videoFileReader)
frame = videoFileReader();
[points,validity] = tracker(frame);
out = insertMarker(frame,points(validity, :),'+');
videoPlayer(out);
disp(points);
And my video file is look like below.
videoFileReader = vision.VideoFileReader('ex.mp4');
videoPlayer = vision.VideoPlayer('Position',[1,10,1280,720]);
and postion of points armention below:
[shoulder_X,shoulder_Y]= ginput(1);
[elbow_x,elbow_y]= ginput(1);
[wrist_x,wrist_y]= ginput(1);
using those code i can fill the parameters for insertShape();but where to put it to work while video playing.
Right after you inser the marker is fine! Something like this (notice how i reassign out):
tracker = vision.PointTracker('MaxBidirectionalError',1);
initialize(tracker,pos,objectFrame);
while ~isDone(videoFileReader)
frame = videoFileReader();
[points,validity] = tracker(frame);
out = insertMarker(frame,points(validity, :),'+');
out = insertShape(out,'Line',position) % Where position is for one or more disconnected lines, an M-by-4 matrix, where each four-element vector [x1, y1, x2,y2], describe a line with endpoints, [x1 y1] and [x2 y2].
videoPlayer(out);
disp(points);
it's work initialy,but it's not move when start the video.
tracker = vision.PointTracker('MaxBidirectionalError',1);
initialize(tracker,pos,objectFrame);
while ~isDone(videoFileReader)
frame = videoFileReader();
[points,validity] = tracker(frame);
out = insertMarker(frame,points(validity, :),'+');
out = insertShape(out,'Line',[shoulder_X shoulder_Y elbow_x elbow_y elbow_x elbow_y wrist_x wrist_y wrist_x wrist_y shoulder_X shoulder_Y] ); % Where position is for one or more disconnected lines, an M-by-4 matrix, where each four-element vector [x1, y1, x2,y2], describe a line with endpoints, [x1 y1] and [x2 y2].
videoPlayer(out);
disp(points);
end
Start Pos:
when video playing: Markers are move according to the video.but lines not
I think postions of insertshape() not updated while video playing.
In insertMarker() it works.
You need to update the variables in the while loop. You are still calling their initial values.
yep,Now i am trying to get that values from the variable 'points'
In below code i display those variable values(x,y) using 'points'
I need to get those values to array and access those values seperately,How can i extract values from that?
this line - > disp(points); show all the x,y values of the movement.I need to get those values to the array.How can i do that?inside thise while loop.
tracker = vision.PointTracker('MaxBidirectionalError',1);
initialize(tracker,pos,objectFrame);
points = detectMinEigenFeatures(rgb2gray(objectFrame));
while ~isDone(videoFileReader)
frame = videoFileReader();
[points,validity] = tracker(frame);
out = insertMarker(frame,points(validity, :),'+','size',10);
out = insertShape(out,'Line',[shoulder_X shoulder_Y elbow_x elbow_y elbow_x elbow_y wrist_x wrist_y wrist_x wrist_y shoulder_X shoulder_Y] ); % Where position is for one or more disconnected lines, an M-by-4 matrix, where each four-element vector [x1, y1, x2,y2], describe a line with endpoints, [x1 y1] and [x2 y2].
videoPlayer(out);
disp(points);
end
I tried to create array and put those values on to it,but it didnt work.
if I able to get those values seperately i will able add those values to 'InsertShape() method and move lines dynamically'
When i display the points inside the while loop, it show like this.
I need to get those values to array,How can i do that inside this while loop?
s.PNG
This example should solve your question:
points = rand(3,2)
idx = 1;
for ii = 1:size(points,1)
for jj = 1:size(points,2)
array(idx) = points(ii,jj);
idx = idx + 1;
end
end
array
Thanks for help,
I able to store the values in to array,
ex_points{num_frame} = points;
then i try to print it using below code,
disp(hist_points{5});
the result was loki below,
w.PNG
How can i get values seperately from this reslut??
I need result like each point x and y value seprately,In above image show 3 points at a one time.
got it,It works now as i want.Thanks for the continues help.

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!