%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Author: Roland Miezianko (rmiezian@astro.temple.edu)
% Date: Spring 2003
% Instructor: Dr.Longin Jan Latecki
% Course: CIS 750
% Project : Assignment 2
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function []=MotionDetection(aviFileName)

% % assign a frame prefix
imageFileNamePrefix = 'frame_';
% % generate individual frames from the avi file in the current directory
% % and store the total number of frames generated
noOfFrameImages = GenerateFrames(aviFileName,imageFileNamePrefix);
% noOfFrameImages = 386; % store the value here, so we don't have to regenerate bmps
noOfFrameImages

% ***************************
% compute the histogram difference values
HistDiffVals = GetHistogramDiff(imageFileNamePrefix, noOfFrameImages);
%HistDiffVals
Threshold = max(HistDiffVals(:,2)) - (max(HistDiffVals(:,2)) - mean(HistDiffVals(:,2)))/2;
HistMotionFrames = GetMotionFrames( HistDiffVals, Threshold );
% plot the result
figure; plot(HistDiffVals(:,1),HistDiffVals(:,2)); 
xlabel('Frame Number'); ylabel('Histogram Difference Value'); title(aviFileName,'FontSize',12,'Color','b')
figure; plot(HistMotionFrames); 
xlabel('Frame Number'); ylabel('Hist Motion Frame Value'); title(aviFileName,'FontSize',12,'Color','b')


% ***************************
% compute the pixel difference values
PixDiffVals = GetPixelDiff(imageFileNamePrefix, noOfFrameImages);
%PixDiffVals
Threshold = max(PixDiffVals(:,2)) - (max(PixDiffVals(:,2)) - mean(PixDiffVals(:,2)))/2;
PixMotionFrames = GetMotionFrames( PixDiffVals, Threshold );
% plot the result
figure; plot(PixDiffVals(:,1),PixDiffVals(:,2)); 
xlabel('Frame Number'); ylabel('Pixel Difference Value'); title(aviFileName,'FontSize',12,'Color','b')
figure; plot(PixMotionFrames); 
xlabel('Frame Number'); ylabel('Pix Motion Frame Value'); title(aviFileName,'FontSize',12,'Color','b')


return;
