Machine Learning Based Object Tracking

Machine learning based object detection as well as tracking that object have been performed in this paper. The authors were able to set a range of interest (ROI) around an object using Open Computer Vision, better known as OpenCV. Next a tracking algorithm has been used to maintain tracking on an object while simultaneously operating two servo motors to keep the object centered in the frame. Detailed procedure and code are included in this paper.


Introduction
The Raspberry Pi is still selling for a large premium due to the worldwide supply and demand issues.At the time of this report there are still no primary vendors that that had a Raspberry Pi 4b 8gb.We started looking around at the Raspberry Pi alternatives.There are two manufacturers that stand out on paper.The first was a company that makes a product called the Orange Pi, the second is a company that makes a product called the Rock Pi, they have recently dropped the Pi from their name.After purchasing the Rock 4c+ we realized that it and the Raspberry Pi were greatly different in the software side and compatibility of things.This forced us to the secondary market where the prices were at least triple what the MSRP was.
After purchasing the Raspberry Pi 4b 8gb, cooling case, monitor and cables needed.We got to work on installing software, starting to look at code and research the best means to bring our project to fruition.Our first snag came when just trying to install the necessary software, luckily one of the reasons we bit the bullet and paid the money for a Raspberry Pi was that the community is robust.You can find help tutorials and software across the Internet.Unfortunately, that also meant an information overload, we would start installing a set of software which is referred to as packets.
These packets wouldn't always be compatible with other packets that we installed and expected them to work with.We would get going on something and find that the time frame of the information was already outdated, and the new software versions wouldn't work with other software versions anymore.Sometimes having the latest and greatest version wouldn't always be beneficial as there wouldn't be a lot of information on it or the workarounds weren't there for bugs that were encountered.It took some trial and error to find the editions that we decided to go with.
One method of safeguarding is to create virtual environments within the folder structure of the Raspberry Pi.This creates a place where you can install different software versions and not have it affect or corrupt the base Raspberry Pi operating system, which was called Raspbian, and its stability.You could essentially Muck up a whole virtual build and instead of starting from scratch and losing all the information on your Pi, such as your codes, you could just delete the virtual environment and create a new one.
In the beginning we started off with the Raspbian 32-bit OS, we decided after encountering so many issues with packet compatibility and software execution stability that we would start with an OS base that had been tried and tested with plenty of resources and support.Raspberry Pi has recently come out with a 64-bit operating system, which it renamed Raspberry Pi OS, about a year ago.We were worried however that the bugs would not have been worked out yet.We would later re-examine that after learning how much faster a 64-bit OS would be vs its predecessor and find some good resources.Most information we examined put the 64-bit OS with our Pi at about a 25% performance increase.
Our software selection took a little bit of trial and error, before and after the OS swap.The software we decided to use to execute our plan is listed in the section previous.By the time we decided to go with a 64-bit version we had become pretty good at using the Raspberry Pi system and community to find solutions to our software issues.The 64-bit system came with some fundamental packet changes that affected the Python operation code we developed.The camera had gone from the legacy raspicam software packets to a newer packet system called libcamera which featured a code called picamera2.This change in the packet library caused us to make some changes to the fundamental code that grabs and shows images from the camera sensor.
The physical wiring of the whole system and installing it on the case is all simple there is a nice mounting system in the case with cutouts for all the I/O on the raspberry pi the case came with a nice adapter that allows the 40 pin General Purpose Input Output (GPIO) pins to be accessed on the side.This 40-pin diversion adapter gave us the ability to mount the pan tilt Hat on the side of the case, as the hats take up all 40 pins.This Hat board also comes with pins that can still utilize the Pi's unused 40 pin GPIO.The head of the pan tilt camera has two servos mounted perpendicular on X and Y axes.The system has two cables to operate the servo motors, one cable to connect the camera, fan power cable, a USB-C power cable, and a display cable for the monitor.We went with a USB Bluetooth keyboard and mouse and the system sits on a wooden frame.
The code that we developed after some grueling trial and error turned out to be straight forward.
It will be listed in the supplements at the end with notations.The basics of the code are to start the camera capture a frame, draw a box over a range of interest (ROI), use a built-in algorithm to track ROI, start a loop that captures frames, determines the center of the frame determines the center of the ROI, takes the error, and adjust the servos accordingly to minimize that error.Thus, keeping the ROI in the center of the frame.This process will have further detail in the procedures.

Procedure
Here importing servo library and other libraries are needed at the beginning of the program.After that we added some more setup code here, we declare dimension dispH and dispW which we will call up later for the frame.Also, we added variables and initial starting values for your servo motors.After the camera configuration we added the tracker variable and attached the OpenCV code to it.We added the code for capturing a single frame.Next, we declared a bounding box variable and have OpenCV bring up a window to select a Range of Interest (ROI).Then just below that we initialized the tracker and kill the selector window.Back in the while loop just after the image grab, we added a line that checks for a successful range of interest in the tracker.After that we tell the program to assign x,y,w,h variables to the associated points within the bounding box

 2  2 
Software: Raspberry Pi: Model 4b o Quad Core Cortex-A72(ARM v8) 64-bit @1.8GHz o 8 Gb RAM o Dual Band IEEE 802.11ac wireless o Bluetooth 5.0 o Gigabit Ethernet o 2 x USB 3.0 2 USB 2.0 ports o RPi standard 40 Pin GPIO header o 2 x micro-HDMI ports support up to 4k @ 60 Hz o 2 Lane MIPI DSI o 2 Lane MIPI CSI o 5v USB-C power connector (min 3A) Sd card 64Gb (> 32 Gb or more recommended)  Sun founder Pan Tilt camera Set o Frame o Pan-tilt Hat o 2 x Servo Motors o Camera Module (5Mp) o FCC Cable (MIPI cam cables)  Micro HDMI to HDMI Cable  Micro HDMI to MINI HDMI Cable  Raspberry Pi compatible Switching USB-C 5v 3.6A Power Supply  Traveling monitor o Power Supply  Raspberry "bullseye" 64 bit with desktop v. 5.15  Python 3.9.Open Computer Vision 4.7.Thonny (Python Integrated Development Environment)  Numpy v. 1.19.2