% CIS 849 -- Homework #2 outline input_movie_name = 'hw2_sign_halfgray.avi'; output_movie_name = 'out.avi'; % get number of input movie frames input_movie_info = aviinfo(input_movie_name); % open output movie output_movie = avifile(output_movie_name, 'Compression', 'None'); % pick corner points of rectangle to track first_frame = aviread(input_movie_name, 1); imshow(first_frame.cdata); [x1, y1] = ginput(4); % (1) initialize Kalman filter: set Phi, H, Q, R, z0, x0, P0 appropriately % ??? %[x, P, PP, loglike] = kalman_update(Phi, H, Q, R, z0, x0, P0, 'initial', 1); % loop over rest of input movie frames for i=1:input_movie_info.NumFrames % read current input frame input_frame = aviread(input_movie_name, i); % (2) process to get a measurement vector z -- treat input_frame.cdata(:, :,1) like a grayscale image % canny_im = edge(input_frame.cdata(:, :,1), 'Canny'); % for example, Canny edge detection % ??? % update Kalman filter state estimate with measurement z (uncomment once steps 1 & 2 are done) % [x, P, PP, loglike] = kalman_update(Phi, H, Q, R, z, x, P); % draw curent image im = frame2im(input_frame); imshow(im), hold on; % (3) overlay current state as a quadrilateral h = plot([x1; x1(1)], [y1; y1(1)], 'r*-'); % as an example, this just draws the initial corners % ??? output_frame = getframe; hold off; % write movie frame output_movie = addframe(output_movie, output_frame); % print what frame we're on i end % finish writing movie output_movie = close(output_movie);