Another interesting behavior of your tracked robot is the ability to find motion. Here is the first part of the code to use the OpenCV library and your webcam to follow motion:
The following is the second part of the code to use the OpenCV library and your webcam to follow motion:
It is useful to look at the code in detail. This first section of the code is very similar to the setup code you used in the colored object section:
#!/usr/bin/env python
: This line allows the program to be executed as a regular program.import cv
: This line imports the OpenCV library.capture = cv.CaptureFromCAM(0)
: This opens the connection towebcam(0)
.cv.NamedWindow("Target", 1)
: This creates a window on the display with the name asTarget
.frame = cv.QueryFrame(capture)
: This grabs an image from the webcam and sticks it in the variable frame.frame_size = cv.GetSize(frame)
: This returns the frame size of the image as a tuple (set of two numbers) of width and height.color_image...