Lab 1: Optical flow

428/615, Martin Jagersand

Submit code and report electronically through the upload link on the e-Class course webpage.
Marks may be given for any of the questions in the assignment, so please answer them all
(many only require a one sentence answer).
Demo: In your lab session.


Exercise 1 (3): Image differences

a (1). Capture images

Write a function to capture a sequence of images using Matlab .
Open Matlab and install following packages: here
vid = videoinput('dcam', 1, 'F7_YUV422_812x612_mode1');
vid.FramesPerTrigger = 1;
vid.ReturnedColorspace = 'rgb';
preview(vid);
in the command window to create a firewire camera pipeline, then you can capture one frame using:
start(vid);
stoppreview(vid);
imwrite(getdata(vid), 'image_path_to_save');
where success is a flag that indicates whether the image capture was successful.

Write a function to capture a sequence of images using Python .
import cv2
cam = cv2.VideoCapture(0, cv2.CAP_FIREWIRE)
ret_val, img = cam.read()
cv2.imwrite(filename, img)

b (2). Image differences

Compute the temporal image derivatives approximated by successive image differences. In the case of a fixed camera and a moving object (e.g. person walking by), try to reliably threshold the temporal derivative to extract only the moving object.

Exercise 2 (7): Optical flow

Solve for the optic flow. Write a routine that outputs the optic flow vectors given an image sequence. Try for both moving camera and moving objects. Chapter 9 from Stockman and Shapiro has a basic presentation of the required concepts: Motion from 2D Image Sequences. Read the introductory sections cursorily. Pay attention to the definitions in Section 9.3 and then closely look at the optic flow equations in Section 9.3.5

If you are getting inconsistent results, you could try testing with artificial motion first. For example:

%im1 = image at time 1
%im2 = image at time 2
im2 = zeros(size(im1));
im2(1:end-1, 1:end-1) = im1(2:end, 2:end);
You may also find it useful to display some of your intermediate images/data.

Exercise 3 (Bonus - 2): High dimensional motion
Try to extract 3-6 dimensional motion. Parameterize motion using e.g. 4 (x,y,rotation,scale) and 6 (affine) parameters. How many motion parameters can be reliably extracted? How does the block size affect the results? Try both camera motion and object motion sequences. Compare results.

Test sequences (Use as desired — It is not mandatory for you to submit results on them)