Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Convert .avi to .bin (binary) file

590 views
Skip to first unread message

Chris

unread,
May 2, 2010, 12:13:04 PM5/2/10
to
Hello!! :) :)

Do you know how to convert .avi file to .bin (binary) file?

I want to use it in a method "Tracking Cars Using Optical Flow".

Thaank you :) :)

us

unread,
May 2, 2010, 4:33:05 PM5/2/10
to
"Chris " <chri...@hotmail.com> wrote in message <hrk8ag$f3a$1...@fred.mathworks.com>...

one of the solutions
- a very brief example

fnam='your.avi';
ao=mmreader(fnam);
frm=read(ao);
imagesc(frm(:,:,:,1));
axis image;
% now, you can save each FRM as a binary into another file...

us

Chris

unread,
May 3, 2010, 1:55:09 AM5/3/10
to
Hellooo!! :) :)

Thank you very much!! Now I can separate the .avi to its image frames..

But how can I make a final .bin file (equal to the initial .avi file) ??

Chris

unread,
May 3, 2010, 1:56:07 AM5/3/10
to

Steven Lord

unread,
May 3, 2010, 9:48:57 AM5/3/10
to

"Chris " <chri...@hotmail.com> wrote in message
news:hrk8ag$f3a$1...@fred.mathworks.com...

Well, since as far as I know .bin is not a standard format, I define it to
be exactly the same as the AVI format to make the solution easy.

movefile('myfile.avi', 'myfile.bin')

If you have a specific format in mind when you say ".bin (binary) file",
then you will need to obtain and/or write the functions to write data to and
read data from files in that specific format.

--
Steve Lord
sl...@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ


Chris

unread,
May 3, 2010, 12:00:23 PM5/3/10
to
Thank you very much, but it does not seem to work...

This demo :

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

uses 'viptraffic.bin' as the video input, but it's not clear how it was converted from the original 'viptraffic.avi' which is included as well in

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

....In this way, I cannot use my own file in this demo...which is unbelievable!! :0

us

unread,
May 3, 2010, 12:16:07 PM5/3/10
to
"Chris " <chri...@hotmail.com> wrote in message <hrmrun$rea$1...@fred.mathworks.com>...

well...
NOW you're (finally) being more specific...
it would have been helpful had you mentioned this tbx from the very beginning...

in the doc, look at the help for

video.BinaryFileReader
video.BinaryFileWriter

us

Chris

unread,
May 3, 2010, 12:45:16 PM5/3/10
to
I read it several times but I cannot use my own video (.avi) file in this demo...

But it should be done somehow...

I'm sorry but I cannot figure it out...

Thank you so much for your help.

Steven Lord

unread,
May 3, 2010, 1:22:01 PM5/3/10
to

"Chris " <chri...@hotmail.com> wrote in message
news:hrmrun$rea$1...@fred.mathworks.com...

That demo should include some mention of how to format the file that it
reads in (or at least a link to that documentation.) Please contact
Technical Support and ask them for more information on how to convert your
file to that format. When you do so, ask them to enter an enhancement
request to include that information in the demo (either directly or via
hyperlink.)

us

unread,
May 3, 2010, 3:12:23 PM5/3/10
to
"Steven Lord" <sl...@mathworks.com> wrote in message <hrn0nn$ggg$1...@fred.mathworks.com>...

steve
it's all there, eg, the writer...

http://www.mathworks.com/access/helpdesk/help/toolbox/vipblks/ref/video.binaryfilewriterclass.html

the OP simply needs to carefully look at the:
- videoformat
- fourcharactercode
tags and the accompanying web-address...

us

Chris

unread,
May 3, 2010, 3:41:07 PM5/3/10
to
US, did you make it??

You managed to use your own file at the demo???

Please tell us :) :)

By the way, I contacted the technical support...!!

wi...@mathworks.com

unread,
May 4, 2010, 8:12:46 AM5/4/10
to
Hi,

If you replace the BinaryFileReader with MultimediaFileReader:

http://www.mathworks.com/access/helpdesk/help/toolbox/vipblks/ref/video.multimediafilereaderclass.html

you will be able to read in other video types.

The MultimediaFileReader can handle many formats (including compressed AVIs) on Windows but only
uncompressed AVIs on Unix. The binary file viptraffic.bin is supported across all platforms,
and that's why it was used for this demo.

Witek

Chris

unread,
May 4, 2010, 8:52:04 AM5/4/10
to
Thank you very much Witek.

I used it but in the final steps of the code there was an error, which forces Matlab to restart...

I do not know why...

Thank you so much for your help...

I do not know how to use my own .avi video yet....

wi...@mathworks.com

unread,
May 5, 2010, 2:32:02 PM5/5/10
to
Hi Chris,

If you can post the error, maybe we can help you. If you are not seeing an error and instead MATLAB exits,
consider running it with -logfile switch:

matlab -logfile my_favorite_file_name.txt

and then looking into the file for errors.

I hope that you were able to incorporate your AVI file into the demo. In terms of mechanics of reading
the file in, a good start is the example that comes with the MultimediaFileReader object:

% EXAMPLE: Read a video and play it.
hmfr = video.MultimediaFileReader('viplanedeparture.avi');
hp = video.VideoPlayer;
while ~isDone(hmfr)
videoFrame = step(hmfr);
step(hp, videoFrame);
end
release(hp);
release(hmfr);

HTH,

Witek

Chris

unread,
May 6, 2010, 1:13:03 AM5/6/10
to
Thank you very much Witek!! :)

I believe the problem is that I cannot even read and play my own video..I tried your example ( Read a video and play it), with my own .avi file in the workspace that I have chosen, eg :

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

(where there are all the example videos!!)

but I get the following error :

MATLAB crash file:C:\Users\Chris\AppData\Local\Temp\matlab_crash_dump.4004:


------------------------------------------------------------------------
Segmentation violation detected at Thu May 06 08:09:16 2010
------------------------------------------------------------------------

Configuration:
MATLAB Version: 7.10.0.499 (R2010a)
MATLAB License: 161051
Operating System: Microsoft Windows 7
Window System: Version 6.1 (Build 7600)
Processor ID: x86 Family 6 Model 15 Stepping 2, GenuineIntel
Virtual Machine: Java 1.6.0_12-b04 with Sun Microsystems Inc. Java HotSpot(TM) Client VM mixed mode
Default Encoding: windows-1252

Fault Count: 1

Register State:
EAX = 00000000 EBX = 0e20fac8
ECX = 00c2c600 EDX = 26f50001
ESI = 20532ccc EDI = 0e20fb24
EBP = 0e20fb30 ESP = 00c2c5e0
EIP = 30e82176 FLG = 00010216

Stack Trace:
[0] ffdshow.ax:0x30e82176(1, 83, 0, 0)

If this problem is reproducible, please submit a Service Request via:
http://www.mathworks.com/support/contact_us/ts/help_request_1.html

A technical support engineer might contact you with further information.

Thank you for your help. MATLAB may attempt to recover, but even if recovery appears successful,
we recommend that you save your workspace and restart MATLAB as soon as possible.

Then I choose "Attempt to continue" and I get the above error along with :
Caught MathWorks::System::FatalException
[Please exit and restart MATLAB]>>

Thank you sooo much :) :)
You have been really helpful :) :)

wi...@mathworks.com

unread,
May 7, 2010, 11:52:22 AM5/7/10
to
Hi Chris,

Having that stack trace below helps a lot. Notice the line about ffdshow.

The MultimediaFileReader object relies on OS libraries and codecs installed on your system to read
the multimedia files. It looks like the failure is happening in the ffdshow, which is a 3rd
party piece of software. I'm guessing that you installed a larger codec pack on your system and
either there is an issue with ffdshow or an interaction between the system object and the ffdshow.

Try uninstalling ffdshow thus allowing your AVI to be handled by another codec on your system.
BTW. Can you play your file with Windows Media Player?

HTH,

Witek

Chris

unread,
May 7, 2010, 12:19:04 PM5/7/10
to
Ohhh thank you soooooo much :) :) :)
You are the best!!
I finally managed to read my own .avi file with MultimediaFileReader!!

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...You reallyyy helped me so much.

Chris

unread,
May 9, 2010, 6:52:03 AM5/9/10
to
Actually when I enter the last Stream processing loop :


while ~isDone(hbfr)

..................


end


I get the error :


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


Even if I enter only the very first part of the loop :

while ~isDone(hbfr)
[y, cb, cr] = step(hbfr); % Read input video frame
[cb, cr] = step(hcr, cb, cr);
imrgb = step(hcsc1, cat(3,y,cb,cr)); % Convert image from YCbCr to RGB
image = step(hidtc, imrgb); % Convert image to single
I = step(hcsc2, image); % Convert color image to intensity
of = step(hof, I); % Estimate optical flow
end

or

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

I also get the same error...

Thank you so much.

wi...@mathworks.com

unread,
May 10, 2010, 11:17:52 AM5/10/10
to
Chris,

The .bin file reader 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

unread,
May 11, 2010, 11:30:22 AM5/11/10
to
Witek thank you so much for your focus and help. :) :)

I managed to add my own video using the following code :

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

image = step(hidtc, my_rgb_frame);
I = step(hcsc2, image);

of = step(hof, I); % Estimate optical flow

Thank you sooooo much!! I wish you the best.

Chris

Zach Chipman

unread,
Jun 23, 2011, 12:37:05 PM6/23/11
to
wi...@mathworks.com wrote in message <hs9830$rut$1...@fred.mathworks.com>...

I am also struggling to use my own video. My code so far is as follows:
while ~isDone(hbfr)
% [y, cb, cr] = step(hbfr); % Read input video frame
% [cb, cr] = step(hcr, cb, cr); % Upsample chroma to construct YCbCr 4:4:4
% image = step(hcsc, cat(3,y,cb,cr)); % Convert image from YCbCr to RGB
% % for display purposes

[y] = step(hbfr); % Read input video frame
image = step(hbfr); % Convert image from YCbCr to RGB
% for display purposes

Did I complete the following correctly?


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).

Thanks a million, Zach

wi...@mathworks.com

unread,
Jun 28, 2011, 11:56:07 AM6/28/11
to
Zach,

> I am also struggling to use my own video. My code so far is as follows:
> while ~isDone(hbfr)
> % [y, cb, cr] = step(hbfr); % Read input video frame
> % [cb, cr] = step(hcr, cb, cr); % Upsample chroma to construct YCbCr 4:4:4
> % image = step(hcsc, cat(3,y,cb,cr)); % Convert image from YCbCr to RGB
> % % for display purposes
>
> [y] = step(hbfr); % Read input video frame
> image = step(hbfr); % Convert image from YCbCr to RGB
> % for display purposes

It's hard for me to tell what's happening without having more context. What kind of file are you
reading in? Can you show more of your code? Can you reproduce it with one of the example video files
shipping with MATLAB?

> [y] = step(hbfr); % Read input video frame
> image = step(hbfr); % Convert image from YCbCr to RGB

Note also that you are calling step on the same (hbfr) object. Is this what you intended?

Witek

Muhammad

unread,
Jul 22, 2011, 8:55:11 AM7/22/11
to
Hi Chris,

I am facing the same problem you faced 1 year back. I can't load my own .avi file. Would you please send me your whole customized code?

I will be ever grateful to you. Thanks in advance.

Ashfaq

Shane

unread,
Sep 5, 2011, 10:23:10 AM9/5/11
to
"Chris " <chri...@hotmail.com> wrote in message <hrk8ag$f3a$1...@fred.mathworks.com>...

I am using Matlab R2011a version. It came supplied with a demo called videotrafficgmm.m where it detects cars in a video sequence using foreground detection based on gaussian mixture models. My problem is similar to the issue you have here! I am trying to adapt the code and use my own .avi video. From reading the replies in this thread, I see that it is best not to try to convert the avi into binary format but that it is easier to adapt the code where the YCbCr components are found.

Could someone please help me with this?

I understand that I need to do this correctly first
1. use a single variable to store the RGB 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).

I am unsure as to how to adapt it to suit my own avi.

Please help!!!! Here is the code from the demo supplied in the matlab package.

%%
% Create a System object to read video from a binary file.
hbfr = vision.BinaryFileReader('Filename', 'viptraffic.bin');

%%
% Create a System object to upsample the chrominance components of the
% video.
hcr = vision.ChromaResampler(...
'Resampling', '4:2:0 (MPEG1) to 4:4:4', ...
'InterpolationFilter', 'Pixel replication');

%%
% Create color space converter System objects to convert the image from
% YCbCr to RGB format.
hcsc = vision.ColorSpaceConverter('Conversion', 'YCbCr to RGB');

%%
% Create a System object to detect foreground using gaussian mixture models.
hof = vision.ForegroundDetector(...
'NumTrainingFrames', 5, ... % only 5 because of short video
'InitialVariance', (30/255)^2); % initial standard deviation of 30/255

%%
% Create a blob analysis System object to segment cars in the video.
hblob = vision.BlobAnalysis( ...
'CentroidOutputPort', false, ...
'AreaOutputPort', true, ...
'BoundingBoxOutputPort', true, ...
'OutputDataType', 'single', ...
'NumBlobsOutputPort', false, ...
'MinimumBlobAreaSource', 'Property', ...
'MinimumBlobArea', 250, ...
'MaximumBlobAreaSource', 'Property', ...
'MaximumBlobArea', 3600, ...
'FillValues', -1, ...
'MaximumCount', 80);

%%
% Create and configure two System objects that insert shapes, one for
% drawing the bounding box around the cars and the other for drawing the
% motion vector lines.
hshapeins1 = vision.ShapeInserter( ...
'BorderColor', 'Custom', ...
'CustomBorderColor', [0 255 0]);
hshapeins2 = vision.ShapeInserter( ...
'Shape','Lines', ...
'BorderColor', 'Custom', ...
'CustomBorderColor', [255 255 0]);

%%
% Create and configure a System object to write the number of cars being
% tracked.
htextins = vision.TextInserter( ...
'Text', '%4d', ...
'Location', [0 0], ...
'Color', [255 255 255], ...
'FontSize', 12);

%%
% Create System objects to display the results.
sz = get(0,'ScreenSize');
pos = [20 sz(4)-300 200 200];
hVideoOrig = vision.VideoPlayer('Name', 'Original', 'Position', pos);
pos(1) = pos(1)+220; % move the next viewer to the right
hVideoFg = vision.VideoPlayer('Name', 'Foreground', 'Position', pos);
pos(1) = pos(1)+220;
hVideoRes = vision.VideoPlayer('Name', 'Results', 'Position', pos);

line_row = 22; % Define region of interest (ROI)

%% Stream Processing Loop
% Create a processing loop to track the cars in the input video. This
% loop uses the previously instantiated System objects.
%
% When the BinaryFileReader object detects the end of the input file, the loop
% stops.


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

[cb, cr] = step(hcr, cb, cr); % Upsample chroma to construct YCbCr 4:4:4

image = step(hcsc, cat(3,y,cb,cr)); % Convert image from YCbCr to RGB

% for display purposes

% Remove the effect of sudden intensity changes due to camera's
% auto white balancing algorithm.
y = im2single(y);
y = y-mean(y(:));

fg_image = step(hof, y); % Foreground

% Estimate the area and bounding box of the blobs in the foreground
% image.
[area, bbox] = step(hblob, fg_image);
Idx = bbox(1,:) > line_row; % Select boxes which are in the ROI.

% Based on dimensions, exclude objects which are not cars. When the
% ratio between the area of the blob and the area of the bounding box
% is above 0.4 (40%) classify it as a car.
ratio = zeros(1, length(Idx));
ratio(Idx) = single(area(1,Idx))./single(bbox(3,Idx).*bbox(4,Idx));
ratiob = ratio > 0.4;
count = int32(sum(ratiob)); % Number of cars
bbox(:, ~ratiob) = int32(-1);

% Draw bounding rectangles around the detected cars.
y2 = step(hshapeins1, image, bbox);

% Display the number of cars tracked and a white line showing the ROI.
y2(22:23,:,:) = 255; % White line
y2(1:15,1:30,:) = 0; % Black background for displaying count
image_out = step(htextins, y2, count);

step(hVideoOrig, image); % Original video
step(hVideoFg, fg_image); % Foreground
step(hVideoRes, image_out); % Bounding boxes around cars
end

% Close the video file
release(hbfr);

wi...@mathworks.com

unread,
Sep 6, 2011, 9:45:12 AM9/6/11
to
Hi,

Hopefully, this will clarify things:

New version of MATLAB has just been released. It ships with the demo that is now using AVI files
instead of BIN files. BTW. You don't need to upgrade MATLAB if you don't want to. You can find
the new demo and the code for it here:

http://www.mathworks.com/products/computer-vision/demos.html?file=/products/demos/shipping/vision/videotrafficgmm.html

Please note that if you run this new version of the demo in older version of MATLAB, it will not
work right away. There has been a change of coordinate system used by the toolbox to make it
consistent and easier to use together with the Image Processing Toolbox. More info can be found here:

http://www.mathworks.com/help/toolbox/vision/rn/bs03omb.html#bs03on2

Ideally, you'd use the new version, but if you can't, you'll have to tweak the code. You'll get
errors that will point you to places that need adjustment.

Please let me know if you experience any issues.

Witek

Shane

unread,
Sep 7, 2011, 11:38:28 AM9/7/11
to
Hi Witek,
Thank you for helping me out with this code. I still have a problem though. When I run the code, the 3 videos are displayed but the video runs only for 32 frames usinf the viptraffic.avi file and also, the results window does not display the bouunding boxes around each car. However, I have not received any error in matlab when I run the code. As mentioned previously, I am using R2011a version.

Please help,
Thanks,
Shane

wi...@mathworks.com wrote in message <j45858$mjl$1...@newscl01ah.mathworks.com>...

wi...@mathworks.com

unread,
Sep 8, 2011, 9:50:57 AM9/8/11
to
Hi Shane,

The fact that you are not seeing the bounding boxes is due to the coordinate system change in 11b.
This code should work for you:

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

%% Tracking Cars Using Gaussian Mixture Models
% This demo illustrates how to detect cars in a video sequence
% using foreground detection based on gaussian mixture models (GMMs).

% Copyright 2004-2010 The MathWorks, Inc.
% $Revision: 1.1.4.6.2.1 $ $Date: 2011/09/02 03:36:26 $

%% Introduction
% This demo illustrates the use of gaussian mixture models to detect
% foreground in a video. After foreground detection, the demo process
% the binary foreground images using blob analysis. Finally,
% bounding boxes are drawn around the detected cars.

%% Initialization
% Use these next sections of code to initialize the required variables and
% System objects.

%%
% Create a System object to read video from avi file.
filename = 'viptraffic.avi';
hvfr = vision.VideoFileReader(filename, 'ImageColorSpace', 'RGB');

%%
% Create color space converter System object to convert the image from RGB
% to intensity format.
hcsc = vision.ColorSpaceConverter('Conversion', 'RGB to intensity');


%%
% Create a System object to detect foreground using gaussian mixture models.
hfdet = vision.ForegroundDetector(...
'NumTrainingFrames', 5, ... % only 5 because of short video
'InitialVariance', (30/255)^2); % initial standard deviation of 30/255

%%
% Create a blob analysis System object to segment cars in the video.
hblob = vision.BlobAnalysis( ...
'CentroidOutputPort', false, ...
'AreaOutputPort', true, ...
'BoundingBoxOutputPort', true, ...
'OutputDataType', 'single', ...
'MinimumBlobArea', 250, ...
'MaximumBlobArea', 3600, ...
'MaximumCount', 80);

%%
% Create System object for drawing the bounding boxes around detected cars.
hshapeins = vision.ShapeInserter( ...
'BorderColor', 'Custom', ...
'CustomBorderColor', [0 255 0]);

%%
% Create and configure a System object to write the number of cars being
% tracked.
htextins = vision.TextInserter( ...
'Text', '%4d', ...
'Location', [1 1], ...
'Color', [255 255 255], ...
'FontSize', 12);

%%
% Create System objects to display the results.
sz = get(0,'ScreenSize');
pos = [20 sz(4)-300 200 200];
hVideoOrig = vision.VideoPlayer('Name', 'Original', 'Position', pos);
pos(1) = pos(1)+220; % move the next viewer to the right
hVideoFg = vision.VideoPlayer('Name', 'Foreground', 'Position', pos);
pos(1) = pos(1)+220;
hVideoRes = vision.VideoPlayer('Name', 'Results', 'Position', pos);

line_row = 23; % Define region of interest (ROI)

%% Stream Processing Loop
% Create a processing loop to track the cars in the input video. This
% loop uses the previously instantiated System objects.
%
% When the VideoFileReader object detects the end of the input file, the loop
% stops.
while ~isDone(hvfr)
image = step(hvfr); % Read input video frame
y = step(hcsc, image); % Convert color image to intensity

% Remove the effect of sudden intensity changes due to camera's
% auto white balancing algorithm.
y = y-mean(y(:));

fg_image = step(hfdet, y); % Detect foreground

% Estimate the area and bounding box of the blobs in the foreground
% image.
[area, bbox] = step(hblob, fg_image);

image_out = image;
image_out(22:23,:,:) = 255; % Count cars only below this white line
image_out(1:15,1:30,:) = 0; % Black background for displaying count

Idx = bbox(1,:) > line_row; % Select boxes which are in the ROI.

% Based on dimensions, exclude objects which are not cars. When the
% ratio between the area of the blob and the area of the bounding box
% is above 0.4 (40%) classify it as a car.
ratio = zeros(length(Idx),2);
ratio(Idx) = single(area(1, Idx))./single(bbox(4, Idx).*bbox(3, Idx));
ratiob = ratio > 0.4;
count = int32(sum(ratiob)); % Number of cars
bbox(:, ~ratiob) = int32(-1);

% Draw bounding rectangles around the detected cars.
image_out = step(hshapeins, image_out, bbox);

% Display the number of cars tracked and a white line showing the ROI.
image_out = step(htextins, image_out, count);

step(hVideoOrig, image); % Original video
step(hVideoFg, fg_image); % Foreground
step(hVideoRes, image_out); % Bounding boxes around cars
end

% Close the video file
release(hvfr);

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

The number of video frames in viptraffic.avi is:

>> VideoReader('viptraffic.avi')

Summary of Multimedia Reader Object for 'viptraffic.avi'.

Video Parameters: 15.00 frames per second, RGB24 160x120.
120 total video frames available.

So you should be seeing 120 frames. Perhaps the code you have was exiting
prematurely due to an error, although you didn't see one, which is suspicious.
Please try the code above and let me know if you still don't get what you
would expect.

Witek

Shane

unread,
Sep 8, 2011, 10:20:11 AM9/8/11
to
Witek,

Thank you so much for your help, very much appreciated. Works perfectly!

wi...@mathworks.com wrote in message <j4ah81$7rj$1...@newscl01ah.mathworks.com>...

sharmah...@gmail.com

unread,
Apr 2, 2016, 4:33:00 PM4/2/16
to
Hey, sorry for taking 6years
I was able to convert any given video to binary file and vice-versa, I am not sure about the efficiency, but it did the work

AVI -> BINARY
hbfw = vision.BinaryFileWriter('output.bin');
videoFReader = vision.VideoFileReader('test.avi');


%%Default is a rgb output, make sure to change it to Ycbcr which is reqd. by binary file writer object
videoFReader.ImageColorSpace= 'YCbCr 4:2:2';


while ~isDone(videoFReader)
[y,cb,cr] = step(videoFReader);
hcr = vision.ChromaResampler('Resampling','4:2:2 to 4:2:0 (MPEG1)');
[cb, cr] = step(hcr, cb, cr);

%%downsample chrominance componenents
%% Just try to change the resampling method according to the size of cb,cr %%expected by step method

%Convert single output to uint8 format(writing stream's requirement)
y= uint8(255*y);cb= uint8(255*cb);cr= uint8(255*cr);

%%%%Send the data to the writing stream hbfw
step(hbfw,y,cb,cr);
end
release(hbfw);



BINARY->AVI
hbfr = vision.BinaryFileReader(path);
%%We should know the output matrix size of a particular frame, which I am %%not sure but it proved right for me as it was coming equal to size of y %%matrix in [y,cb,cr]

hbfr.OutputSize=size(y);

while ~isDone(hbfr)

%%Now resample until you y,cb,cr sizes same
hcr = vision.ChromaResampler('Resampling', '4:2:0 (MPEG1) to 4:4:4');
%%Upsampling object,to bring cb,cr of sime size of y


%%The videoplayer expects a rgb component,so we will converting the modified ycbcr matrix to rgb.
hcsc = vision.ColorSpaceConverter('Conversion', 'YCbCr to RGB'); %%Object of ycbcr color space to rgb as videoplayer requires rgb


[y, cb, cr] = step(hbfr);
[cb, cr] = step(hcr, cb, cr);%%Chrominance upsamplig
video = step(hcsc, cat(3,y,cb,cr));%%rgb conversion
%%Send the videoframe to the videoplayer
step(videoPlayer,video);
end
release(hbfr);
% end
0 new messages