In addition to using the keyboard to control the status of the car, we also wrote a ball tracking code.
sudo apt-get install libatlas-base-dev libjasper-dev libqt4-test libwebp6 libtiff5 libopenexr23 libgstreamer1.0-0 libavcodec-dev libavformat-dev libswscale-dev libqtgui4 -y
sudo pip3 install opencv-python==3.4.6.27
cd ~/SunFounder_PiCar-V/ball_track
python3 ball_tracker.py
After the code runs, find a red ball (at least larger than the diameter of the camera) and put it within 10-50cm range in front of the camera to get the car to follow your ball.
![](https://learn.sunfounder.com/wp-content/uploads/2020/11/image-891.png)
If you want to know whether the car has catched your ball, you can do as follows:
Step 1: Enable the VNC on the Raspberry Pi.
sudo raspi-config
Choose 5 Interfacing Options.
![](https://learn.sunfounder.com/wp-content/uploads/2020/11/image-892.png)
P3 VNC
![](https://learn.sunfounder.com/wp-content/uploads/2020/11/image-893.png)
Yes
![](https://learn.sunfounder.com/wp-content/uploads/2020/11/image-894.png)
Finally select OK->Finish to exit the config.
![](https://learn.sunfounder.com/wp-content/uploads/2020/11/image-896.png)
Step 2: Download the VNC Viewer for your computer and install it.
https://www.realvnc.com/en/connect/download/viewer/
Note: During your installation on your Windows, if you encounter the following prompt, please click Comtinue to continue your installation.
![](https://learn.sunfounder.com/wp-content/uploads/2020/11/image-897.png)
Step 3: Open VNC Viewer you have installed, type in your Raspberry Pi IP address, and press the Enter button.
![](https://learn.sunfounder.com/wp-content/uploads/2020/11/image-898.png)
Step 4: Enter the username and password of your Raspberry Pi on this page, by default, they are pi and raspberry; then click OK.
![](https://learn.sunfounder.com/wp-content/uploads/2020/11/image-899.png)
Step 5: Now, we enter the Raspberry Pi desktop, click Terminal and type the following commands to open the code ball_tracker.py.
cd ~/SunFounder_PiCar-V/ball_track
sudo nano ball_tracker.p
Then modify the code as follows:
Show_image_enable = True
Draw_circle_enble = True
Press Ctrl+X and Y to save the change.
![](https://learn.sunfounder.com/wp-content/uploads/2020/11/image-900.png)
Note: After you finish doing this step, you must log in the Raspberry Pi via VNC, or you can use a monitor; if not, the warning is as follows:
![](https://learn.sunfounder.com/wp-content/uploads/2020/11/image-901.png)
Step 6: Run the ball_tracker.py.
python3 ball_tracker.py
![](https://learn.sunfounder.com/wp-content/uploads/2020/11/image-902.png)
Step 7: After running the code ball_tracker.py, these four images will appear. If you place a red ball in front of the camera, you can see a green circle which represents that the car has catched your red ball.
![](https://learn.sunfounder.com/wp-content/uploads/2020/11/image-904.png)