Car detection with optical flow in MATLAB

  • Follow


Hellooooooooo :) :)

I want to implement car detection with optical flow in MATLAB, as shown in : 

http://www.mathworks.com/products/viprocessing/demos.html?file=/products/demos/shipping/vipblks/videotrafficof.html

but initially, I have to "Create a System object to read video from a binary file" , using the code :

 hbfr = video.BinaryFileReader( ...
        'Filename', 'viptraffic.bin');


, but I have an .avi file that I want to use for car detection... Should I convert .avi to .binary file? I do not understand how to do it...I also get the error ??? Undefined variable "video" or class "video.BinaryFileReader"... when I use the command above...

I am sorry but I cannot understand...

Thank you so much for your help.
0
Reply Chris 5/1/2010 9:48:05 AM

Hi Chris,

The BinaryFileReader object may be used to read raw data streams from a video file.  It will not recognize or react to file formats, headers or compression beyond some basic data layout options, so it's not the best approach for .avi files.

Instead, use the video.MultimediaFileReader object.  This will recognize AVI files and handle data compression based on your platform/OS.

System objects are available beginning with R2010a; the video objects ship with Video and Image Processing Blockset.  If you use an earlier version of MATLAB, you will not be able to work with System objects.  This could be a source of the error message you cite.

--Don

"Chris " <chris_sar@hotmail.com> wrote in message <hrgtck$1g3$1@fred.mathworks.com>...
> Hellooooooooo :) :)
> 
> I want to implement car detection with optical flow in MATLAB, as shown in : 
> 
> http://www.mathworks.com/products/viprocessing/demos.html?file=/products/demos/shipping/vipblks/videotrafficof.html
> 
> but initially, I have to "Create a System object to read video from a binary file" , using the code :
> 
>  hbfr = video.BinaryFileReader( ...
>         'Filename', 'viptraffic.bin');
> 
> 
> , but I have an .avi file that I want to use for car detection... Should I convert .avi to .binary file? I do not understand how to do it...I also get the error ??? Undefined variable "video" or class "video.BinaryFileReader"... when I use the command above...
> 
> I am sorry but I cannot understand...
> 
> Thank you so much for your help.
0
Reply Don 5/1/2010 11:21:07 AM


Thank you so much for your help Don!!! :)

Well it seems that it works with Matlab 2010a, but I cannot understand where the 'viptraffic.bin' file is....

Unfortunately, I cannot use my own .avi file...

And I have a really big problem...

Thank you so muuuch :) :)
0
Reply Chris 5/2/2010 3:12:04 PM

I found the file "viptraffic.bin" (--> binary) and "viptraffic.avi" in

C:\Program Files\MATLAB\R2010a\toolbox\vipblks\vipdemos 

but I want to convert my own .avi file to .bin in order to use it...

Thank you so much!! :)
0
Reply Chris 5/2/2010 4:15:07 PM

Well, I finally managed to read my own .avi file with MultimediaFileReader by uninstalling the k-lite codec pack!!

But now, at the end of the whole algorithm described here :

http://www.mathworks.com/products/viprocessing/demos.html?file=/products/demos/shipping/vipblks/videotrafficof.html#1

When I enter the code :

 % Calculate and draw the motion vectors.
    tmp = of(RV,CV) .* MotionVecGain;
    lines = [X(:)';Y(:)';X(:)' + imag(tmp(:))';Y(:)' + real(tmp(:))'];
    mv_video = step(hshapeins2, image, lines);

    step(hVideo1, image); % Display Original Video
    step(hVideo2, mv_video); % Display video with motion vectors
    step(hVideo3, th_image); % Display Thresholded Video
    step(hVideo4, image_out); % Display video with bounding boxes

I get the error message :

??? Error using ==> step
Reported by video.MultimediaFileReader: Too many output arguments; must be between 1 and 2
(3 requested).

I do not know what this means...

Thank you so much...
0
Reply Chris 5/9/2010 7:20:05 AM

Hi Chris,

I'm reposting my response from your other thread on converting from .bin to .avi format:

========================================================

The .bin file reader in the original demo was set up to output YCbCr color signal that 
was Chroma sub-sampled.
That signal was upsampled and converted to RGB. The YCbCr signal was output into three different
arrays:  Y, Cb and Cr (where Cb and Cr are smaller in size than Y).

When you use the MultimediaFileReader, it gives you RGB output that's packed in a 3-D array, i.e.
single variable output. Therefore, you need to do the following:

1. use a single variable to store you RBB output
2. remove chroma resampling
3. remove color space conversion to RGB since you already have RGB from the MultimediaFileReader
4. apply conversion to intensity on your new RGB signal (you will no longer need the cat(3,y,cb,cr),
   just feed your 3-D RGB signal directly to it).

The error was basically saying: you asked for 3 outputs but I can give you only 1 or 2 (there is a
way to get EOF indicator with this object).

See the documentation for ChromaResampler to learn more about subsampled YCbCr color format.

Your loop:

while ~isDone(hbfr)
    [y, cb, cr] = step(hbfr); % Read input video frame
end

can be quickly made to work like this:

while ~isDone(hbfr)
    my_rgb_frame = step(hbfr); % Read input video frame
end

=========================================================

Hope this helps,

Witek


Chris  <chris_sar@hotmail.com> wrote:
> Well, I finally managed to read my own .avi file with MultimediaFileReader by uninstalling the k-lite codec pack!!
> 
> But now, at the end of the whole algorithm described here :
> 
> http://www.mathworks.com/products/viprocessing/demos.html?file=/products/demos/shipping/vipblks/videotrafficof.html#1
> 
> When I enter the code :
> 
>  % Calculate and draw the motion vectors.
>     tmp = of(RV,CV) .* MotionVecGain;
>     lines = [X(:)';Y(:)';X(:)' + imag(tmp(:))';Y(:)' + real(tmp(:))'];
>     mv_video = step(hshapeins2, image, lines);
> 
>     step(hVideo1, image); % Display Original Video
>     step(hVideo2, mv_video); % Display video with motion vectors
>     step(hVideo3, th_image); % Display Thresholded Video
>     step(hVideo4, image_out); % Display video with bounding boxes
> 
> I get the error message :
> 
> ??? Error using ==> step
> Reported by video.MultimediaFileReader: Too many output arguments; must be between 1 and 2
> (3 requested).
> 
> I do not know what this means...
> 
> Thank you so much...
0
Reply witek 5/10/2010 3:20:53 PM

5 Replies
1868 Views

(page loaded in 0.043 seconds)

Similiar Articles:













7/20/2012 3:09:54 PM


Reply: