11 Try tracking the target

Edit Line 2 of the script track2.m so that the script uses a threshold value to compute the mask images that is suitable for your camera and lighting conditions.

Hold the target up in front of the webcam so that it fills the entire view of the webcam. Remember that your code only looks for the target in the middle part of the image.

Run the script track2 and slowly move the target left and right and up and down. The script uses your MATLAB functions to find the center of mass of the target and adjusts the panning angle of the camera to keep the center of the target in the center of the image. If you keep the paper target in front of the camera without allowing too much of the background from appearing in the image then the camera should follow the target as you move it.

To stop tracking hold the Ctrl key and press the C key in the Command Window.

Type

stopServos

in the Command Window to unpower the servo motors.