Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
video

Subject: video

From: Jessica

Date: 11 May, 2010 17:35:24

Message: 1 of 8

Hi,

I am using mmreader and mplay to view some video files. Does anyone know whether it is possible to create a box that I can move around to different areas of the screen? For example, if I had a video of a person moving, I would like to move the box around, frame-by-frame, so that the box was always centered around the person's head. I would like to do this by dragging the box to the desired location. I don't need to keep track of the coordinates of this box.

Thanks!

Subject: video

From: Walter Roberson

Date: 11 May, 2010 17:43:39

Message: 2 of 8

Jessica wrote:

> I am using mmreader and mplay to view some video files. Does anyone know
> whether it is possible to create a box that I can move around to
> different areas of the screen? For example, if I had a video of a person
> moving, I would like to move the box around, frame-by-frame, so that the
> box was always centered around the person's head. I would like to do
> this by dragging the box to the desired location. I don't need to keep
> track of the coordinates of this box.

There are a lot of different ways to get coordinates into Matlab, such
as ginput(), or by setting a button press callback function for the axis.

The actual drawing of the box onto an existing frame can be done via
rectangle()

Dragging the box around each time sounds kind of tedious. I would be
tempted, in such a case, to see if some light image processing might
work to isolate the head.

Subject: video

From: Jessica

Date: 11 May, 2010 17:55:19

Message: 3 of 8

Walter Roberson <roberson@hushmail.com> wrote in message <fHgGn.3257$0M5.2287@newsfe07.iad>...
> Jessica wrote:
>
> > I am using mmreader and mplay to view some video files. Does anyone know
> > whether it is possible to create a box that I can move around to
> > different areas of the screen? For example, if I had a video of a person
> > moving, I would like to move the box around, frame-by-frame, so that the
> > box was always centered around the person's head. I would like to do
> > this by dragging the box to the desired location. I don't need to keep
> > track of the coordinates of this box.
>
> There are a lot of different ways to get coordinates into Matlab, such
> as ginput(), or by setting a button press callback function for the axis.
>
> The actual drawing of the box onto an existing frame can be done via
> rectangle()
>
> Dragging the box around each time sounds kind of tedious. I would be
> tempted, in such a case, to see if some light image processing might
> work to isolate the head.

Thanks for the quick response! The rectangle() code works well. However, for my purposes, I actually don't want it automated and need to be able to drag the rectangle around to different places on the screen. Any idea how to do this? Thanks!

Subject: video

From: Jessica

Date: 11 May, 2010 17:57:05

Message: 4 of 8

Walter Roberson <roberson@hushmail.com> wrote in message <fHgGn.3257$0M5.2287@newsfe07.iad>...
> Jessica wrote:
>
> > I am using mmreader and mplay to view some video files. Does anyone know
> > whether it is possible to create a box that I can move around to
> > different areas of the screen? For example, if I had a video of a person
> > moving, I would like to move the box around, frame-by-frame, so that the
> > box was always centered around the person's head. I would like to do
> > this by dragging the box to the desired location. I don't need to keep
> > track of the coordinates of this box.
>
> There are a lot of different ways to get coordinates into Matlab, such
> as ginput(), or by setting a button press callback function for the axis.
>
> The actual drawing of the box onto an existing frame can be done via
> rectangle()
>
> Dragging the box around each time sounds kind of tedious. I would be
> tempted, in such a case, to see if some light image processing might
> work to isolate the head.


Also, the rectangle that I drew with rectangle() seems to disappear when I click forward to a new frame. Ideally, I would want the rectangle to remain on the screen all the time.

Subject: video

From: Walter Roberson

Date: 11 May, 2010 18:55:28

Message: 5 of 8

Jessica wrote:

> Also, the rectangle that I drew with rectangle() seems to disappear when
> I click forward to a new frame. Ideally, I would want the rectangle to
> remain on the screen all the time.

for K = 1 : numframe
   thisframe = mmreader(FileName, K, 1);
   if K == 1
     framehandle = image(thisframe);
   else
     set(framehandle, 'CData', thisframe);
     rectangle(Some Appropriate Parameters);
   end
   pause(1/24); %24 frames per second or so...
end


If you use this setup, you will not need "hold on", as rectangle() always adds
to the current axis, and for each frame after the first you update the current
image rather than replacing it.

Subject: video

From: Jessica

Date: 11 May, 2010 23:02:06

Message: 6 of 8

Walter Roberson <roberson@hushmail.com> wrote in message <hsc97i$3be$1@canopus.cc.umanitoba.ca>...
> Jessica wrote:
>
> > Also, the rectangle that I drew with rectangle() seems to disappear when
> > I click forward to a new frame. Ideally, I would want the rectangle to
> > remain on the screen all the time.
>
> for K = 1 : numframe
> thisframe = mmreader(FileName, K, 1);
> if K == 1
> framehandle = image(thisframe);
> else
> set(framehandle, 'CData', thisframe);
> rectangle(Some Appropriate Parameters);
> end
> pause(1/24); %24 frames per second or so...
> end
>
>
> If you use this setup, you will not need "hold on", as rectangle() always adds
> to the current axis, and for each frame after the first you update the current
> image rather than replacing it.

Thanks for this detailed code. I had a little difficulty running it as a number of errors popped up. However, I think it may not actually work for my purposes anyway. When I am looking at the video, I need to use the forward and back buttons to look at different frames in the video. Sometimes I need to go back a few frames, sometimes forward. Any further insights? Thanks!

Subject: video

From: Walter Roberson

Date: 11 May, 2010 23:36:15

Message: 7 of 8

Jessica wrote:

> Thanks for this detailed code. I had a little difficulty running it as a
> number of errors popped up. However, I think it may not actually work
> for my purposes anyway. When I am looking at the video, I need to use
> the forward and back buttons to look at different frames in the video.
> Sometimes I need to go back a few frames, sometimes forward. Any further
> insights? Thanks!

The basics remain the same -- if this is your very first image, then do a real
image() call and save the handle returned from it, and then rectangle() the
box into existence. If this is not your very first image, then instead of
using image() to display the frame, set() the CData property of the saved
handle to the new image, and if the rectangle is to be adjusted in position
then use set() to set the Position properties of the handle of the rectangle.

For efficiency, you should usually update the properties of an existing object
rather (implicitly) deleting the object and creating a new one of the same
type, as is happening in your existing code when you image() a new frame onto
the display.

Subject: video

From: Jessica

Date: 12 May, 2010 11:18:04

Message: 8 of 8

Walter Roberson <roberson@hushmail.com> wrote in message <hscpm1$rgo$1@canopus.cc.umanitoba.ca>...
> Jessica wrote:
>
> > Thanks for this detailed code. I had a little difficulty running it as a
> > number of errors popped up. However, I think it may not actually work
> > for my purposes anyway. When I am looking at the video, I need to use
> > the forward and back buttons to look at different frames in the video.
> > Sometimes I need to go back a few frames, sometimes forward. Any further
> > insights? Thanks!
>
> The basics remain the same -- if this is your very first image, then do a real
> image() call and save the handle returned from it, and then rectangle() the
> box into existence. If this is not your very first image, then instead of
> using image() to display the frame, set() the CData property of the saved
> handle to the new image, and if the rectangle is to be adjusted in position
> then use set() to set the Position properties of the handle of the rectangle.
>
> For efficiency, you should usually update the properties of an existing object
> rather (implicitly) deleting the object and creating a new one of the same
> type, as is happening in your existing code when you image() a new frame onto
> the display.

I'm still having a little trouble with this. When I enter in the code for mmreader:

thisframe = mmreader('video.mov', K, 1);

I get the error:

??? Error using ==> set
Invalid parameter/value pair arguments.

Error in ==> mmreader.mmreader>mmreader.mmreader at 137
                set(obj, varargin{:});
 
Based on above, I'm also not sure how to make it so that I can use the keyboard forward/back to step through the video frame-by-frame AND have the rectangle appear. A few more specific details would be extremely helpful. Thanks!

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us