Tag Archives: Raspberry Pi Camera

AI on the Edge LESSON 16: Control Pan/Tilt Camera Position Using Voice Commands

In AI on the Edge Lesson 16, we take a big step forward by combining voice recognition with physical motion. In this project, you will build a voice-controlled pan/tilt camera system. Using simple spoken commands such as “right,” “left,” “up,” “down,” and “quit,” you can move the Raspberry Pi camera in real time. This lesson brings together the Fusion HAT+ servo control, the Speech-to-Text (STT) capabilities we explored earlier, live video streaming with picamera2 and OpenCV, and multithreading to keep everything running smoothly.
The hardware setup is straightforward. We connect two servos to the Fusion HAT+ — one for pan (horizontal movement) on pin 2 and one for tilt (vertical movement) on pin 3. The Raspberry Pi Camera is mounted on a pan/tilt mechanism so it can physically follow your voice commands. We start the camera at a neutral position (pan = 0°, tilt = -20°) and define step sizes so the movement feels responsive but controlled.
The Python code uses two main threads: one for continuous voice listening and another for displaying the live video feed. In the listening thread, we create an STT object and continuously wait for voice input. When a command is recognized, we adjust the pan or tilt angle accordingly and immediately send the new position to the appropriate servo. The main loop captures frames from the Pi Camera, flips them for correct orientation, displays them in an OpenCV window, and checks for the ‘q’ key to exit gracefully.
This project demonstrates several important concepts working together: real-time voice command processing, servo motor control, camera streaming with picamera2 at 1280×720 resolution and 60 fps, and proper use of threading so that listening and video display do not block each other. You will also notice how we use global variables carefully to share the current pan and tilt positions between the threads.
By the end of this lesson, you will have a working voice-controlled camera that you can point anywhere you want just by talking to it. This is an excellent foundation for more advanced projects such as voice-controlled object tracking, security cameras, or interactive AI assistants that can both see and move.The complete code is provided below, along with explanations of the key sections. Feel free to experiment with different step sizes (xDelta and yDelta), starting angles, or even add new voice commands once you are comfortable with the basic version.
This is the code developed in the video lesson:

 

AI on the Edge LESSON 15: Use the Raspberry Pi Camera in openCV to Create Live Video

Hey everyone, welcome to Lesson 15 of the AI on the Edge series!

In today’s lesson, we take a very important step forward. We finally bring the Raspberry Pi Camera into our OpenCV world so we can capture live video and start building real computer vision projects.  Today we learn how to pull live frames directly from the official Raspberry Pi camera using picamera2 and display them smoothly with OpenCV.

This lesson is all about building a clean, reliable foundation. I walk you through how to properly configure the Pi Camera with the modern picamera2 library — setting the resolution to 1280×720, choosing the right format, and pushing the frame rate up to 60fps. Then we bring those frames straight into OpenCV so we can see live video in a window. You’ll also learn why we use RGB888 format and how to organize your code so it stays clean as our projects get more complex.

Getting reliable live video from the Pi Camera is one of those foundational skills that opens the door to everything we’re going to do in this class — face detection, object tracking, color tracking, motion detection, and all the exciting AI projects still ahead. Once you have solid camera access, the real fun begins.

I kept this lesson straightforward on purpose. I want you to have a rock-solid base that you can build upon without fighting technical problems later. By the end of this video, you’ll have a clean, responsive live video stream running from your Raspberry Pi Camera, ready for all the computer vision magic we’re about to add in the coming lessons.

So fire up your Raspberry Pi, grab your camera module, and let’s get that live video rolling! As always, I encourage you to type the code along with me and experiment with it. Change the resolution, try different frame rates, and make it your own.

Are you ready? Let’s dive in!

In today’s lesson, this is the code which we developed:

This is the schematic we are using in these lessons:

Fusion Hat Circuit Diagram
This is the circuit we will use moving forward in the class

AI on the Jetson Nano LESSON 52: Improving Picture Quality of the Raspberry Pi Camera with Gstreamer

In this lesson we want to pause and work on improving the image quality of the video stream coming from the Raspberry Pi camera. Right now, we are using a boilerplate Gstreamer string to launch the Raspberry Pi camera. In the video above we show how image quality can be drastically improved by tweaking the Gstreamer launch string.

Based on the Video above, we develop a greatly improved image quality by adjusting the Gstreamer launch string. Below, for you enjoyment is the code that will optimize picture quality.

First, this is the key line that results in excellent video quality:

And here is the overall code for running and displaying from the camera with the enhanced quality:

 

Now, once we have optimized the Gstreamer launch stream, we need to consider what path to move forward. In lesson #50 we saw that we could either control the camera using the NVIDIA Jetson Utilities, or we could control the camera normally from OpenCV. The advantage of our old OpenCV method is that it gives us more control of the camera. The advantage of the Jetson Utility method is that it appears to run faster, and for the rPi camera, have less latency. Below are two code examples for the two methods above. In the video lesson above, we will figure out the best strategy by tweaking the parameters in these two programas.

OPTION #1: Launch the cameras using OpenCV

OPTION # 2: Control Camera with NVIDIA Jetson Utilities Library

 

Jetson Xavier NX Lesson 8: Controlling Dual Pan/Tilt Raspberry Pi Cameras


In this lesson we show how to independently control two Raspberry Pi Cameras using servo controlled pan/tilt brackets. This work will serve as the foundation for allowing us to create cameras that scan a room and locate objects of interest.

In this lesson, I am using two pan/tilt camera mounts. You can get the gear I am using on amazon HERE. I suggest purchasing two units.

Then, we also need two Version two raspberry pi cameras. I like the following ones, because they include a neat little acrylic case, and the long cable, which makes it work much better on the pan/tilt bracket. You can get the cameras HERE.

If you do not have a Jetson Xavier NX yet, you can pick up the gear I am using below:

  1. First, you will need the Jetson Xavier NX, which you can get HERE:
  2. You will want a quality, large SD card, I have very good luck with this one HERE:
  3. You will need a camera. I have found that the Jetson Xavier NX works very well with most Logitech Webcams, but these cameras are a little hard to find right now. I suggest the best option if you do not have a logitech webcam is to get the Raspberry Pi Version 2 camera, which works very well. You can pick the camera up HERE.
  4. It is optional, but I have found that it is nice to have an extra, longer cable for the Raspberry Pi camera, which is available HERE. Also, a small case/stand for the camera is nice and you can get the one I use HERE.
  5. The Jetson Nano has a slot for a SSD drive. I really like having the SSD drive attached, and makes it much easier to keep your work backed up. The projects in these lessons will work fine with just the SD card, but if you like, the SSD drive makes life easier (note even with SSD drive, you will still need the SD card above). You can get the SSD drive I am using HERE.
  6. You can use USB keyboard and mouse, but I like to preserve my USB slots for other things, so like using a wireless keyboard and mouse. This is optional, but I have found these work well on the Jetson Xavier NX, and you can get what I am using HERE.
  7. You will need an HDMI cable and monitor, which you probably already have.

 

Jetson Xavier NX Lesson 7: Connecting and Controlling Servos

In this lesson we show you how to control a pan/tilt camera bracket with the NVIDIA Jetson Xavier NX. We go through the physical build of the bracket, how to connect the circuit, and then how to program the servos. We use the Adafruit circuitpython library, and show how to download and use the library. If you want to play along at home, you can pick the pan/tilt bracket and servos up HERE, and you can grab a couple of Raspberry Pi cameras HERE.

Below is the simple code for moving the servo using the Jetson Xavier NX: