/RaspberryPi-Mertracking

Raspberry Pi + OpenCV + Tracking + Trigger Project

Primary LanguagePythonGNU General Public License v3.0GPL-3.0

Detect Motion and Destroy Target!

In this video I show you how to build a DIY motion tracking project with a Raspberry Pi 3. The project is autonomous so it moves and fires the gun when it detects motion. I used laser module for this project, but you can easily change modify this build to use a Nerf instead.This project allows you to detect and track a person with OpenCV and then trigger a device (such as a laser or gun).
Full tutorial for motion tracking: https://youtu.be/iwlfiDtddlg

Demo CountPages alpha

Install Guide

  1. Make sure pip is installed
    https://www.pyimagesearch.com/2018/09/19/pip-install-opencv/

sudo apt-get install python pip

  1. Install OpenCV 3. Follow all steps for python 3 instructions
    https://www.pyimagesearch.com/2016/04/18/install-guide-raspberry-pi-3-raspbian-jessie-opencv-3/

  2. Setup I2C on your Raspberry Pi
    https://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c

  3. Install the Adafruit stepper motor HAT library

sudo pip install git+https://github.com/adafruit/Adafruit-Motor-HAT-Python-Library

  1. If you are using a Raspberry Pi Stepper Motor Expansion Board other than the Adafruit Stepper Motor HAT (just like in the video), then update the I2C address or frequency value with the following. (This address is only compatible with the board in the video, default value is blank for Adafruit Stepper Motor HAT)

self.mh = Adafruit_MotorHAT()   to   self.mh = Adafruit_MotorHAT(0x6F)   in the source code (mertracking.py)

  for mor details: http://www.raspberrypiwiki.com/index.php/Robot_Expansion_Board

  1. Make sure to create your virtual environment with the extra flag

mkvirtualenv cv --system-site-packages -p python3

  1. Source your bash profile

source ~/.profile

  1. Open Terminal and Activate your virtual environment

workon cv

  1. Clone this repository

git clone git@github.com:MertArduino/RaspberryPi-Mertracking.git

  1. Navigate to the directory

cd RaspberryPi-Mertracking

  1. Install dependencies to your virtual environment

pip install imutils RPi.GPIO

  1. Run the Code

python mertracking.py

Setting Parameters

mertracking.py has a couple parameters that you can set

MOTOR_X_REVERSED = False
MOTOR_Y_REVERSED = False
MAX_STEPS_X = 20
MAX_STEPS_Y = 10
RELAY_PIN = 22
self.mh = Adafruit_MotorHAT(0x6f)   I2C Address or Frequency
self.sm_x.setSpeed(5)   Speed of the Stepper Motor 1
self.sm_y.setSpeed(5)   Speed of the Stepper Motor 2
self.sm_x = self.mh.getStepper(200, 1)   Steps/Rev of the Stepper Motor 1
self.sm_y = self.mh.getStepper(200, 1)   Steps/Rev of the Stepper Motor 2
time.sleep(1)   Delay Time for the Relay Trigger

Adafruit_MotorHAT.MICROSTEP   You can change the step type with the following commands

MICROSTEP
SINGLE
DOUBLE
INTERLEAVE