Book Image

Raspberry Pi Robotic Projects - Third Edition

By : Richard Grimmett, Jon Witts
Book Image

Raspberry Pi Robotic Projects - Third Edition

By: Richard Grimmett, Jon Witts

Overview of this book

This book will allow you to take full advantage of Raspberry Pi Zero and Raspberry Pi 3 by building both simple and complex robotic projects. The book takes a mission-critical approach to show you how to build amazing robots and helps you decide which board to use for which type of robot. The book puts a special emphasis on designing mobile (or movable) robots using the Raspberry Pi Zero. The projects will show inexpensive, yet powerful, ways to take full advantage. It will teach you how to program Raspberry Pi, control the movement of your robot, and add features to your robots.
Table of Contents (13 chapters)
Raspberry Pi Robotic Projects - Third Edition
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface

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...