Following your hand
It is essential to be able to see if you want to follow your hand. Fortunately, adding hardware and software for vision is both easy and inexpensive. As you learned in Chapter 2, Building Your Own Futuristic Robot, connecting a USB camera is very easy.
Most importantly, OpenCV and your webcam can track your hand position. OpenCV makes this amazingly simple by providing some high-level libraries that can help us with this task. First, follow the instructions in Chapter 2, Building Your Own Futuristic Robot, to install your USB webcam and OpenCV.
Then you'll create a set of code that looks like this:
#!/usr/bin/python import cv2 import numpy as np import math cap = cv2.VideoCapture(0) cap.set(3, 360) cap.set(4, 240) while(cap.isOpened()): ret, img = cap.read() grey_image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) blur = cv2.GaussianBlur(grey_image, (5,5), 0) ret, thresh1 = cv2.threshold...