IOT Projects

I Made an AI CCTV That Decides When to Record (RDK X5 + YOLOv5)

Last Updated on September 4, 2026 by Engr. Shahzada Fahad

Description:

Modern surveillance systems are moving away from continuous recording toward intelligent, event-based monitoring. An AI CCTV system can reduce storage usage, eliminate false alarms, and make real-time decisions based on what actually matters.

In this article, I explain how I built an AI-powered CCTV system using the RDK X5 and an optimized YOLOv5 model, comparing manual recording with a fully automatic, decision-based surveillance setup.



This is not a normal CCTV camera.

This is an AI CCTV system that decides on its own when something suspicious happens, starts recording automatically, and ignores random movements and false triggers.

In today’s article, I am building two completely different CCTV systems on the RDK X5 by D-Robotics.

One is a manual CCTV system, where I control the recording myself, and the second one is a fully automatic AI-based CCTV system.

Amazon Links:

RDK X5 Development Board

RDK Stereo Camera

High-Quality USB HD Cams

HDMI Screen

Keyboard and Mouse

Other Tools and Components:

ESP32 WiFi + Bluetooth Module (Recommended)

Arduino Nano USB C type (Recommended)

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

WHAT THIS ARTICLE IS ABOUT

In this article, you are not going to see just a camera connected to a board. You are going to see how real CCTV logic is designed.

I am using the RDK X5, running an optimized YOLOv5 AI model, and I will show you the difference between manual control and automatic decision-making.

Both systems are practical, and they solve different problems.

MANUAL CCTV SYSTEM – OVERVIEW

Let’s start with the manual CCTV system. This system uses a USB camera connected to the RDK X5, and the idea is very simple and very realistic.




The camera is always live, AI is always running in the background, but the recording is fully controlled by the user. I can start recording manually, stop it whenever I want, and save the footage just like a traditional CCTV DVR system.

Even though this is called a manual CCTV system, it is not a basic system. AI is still working here.



 

The YOLOv5 model is detecting people in real time, drawing bounding boxes, and adding a proper date and time stamp on the video, exactly like real CCTV footage you see in offices or shops.

MANUAL CCTV – WHY THIS APPROACH IS IMPORTANT

Manual CCTV systems are still extremely important in the real world. In many places, you don’t want automatic recording all the time. You want full control. Shops, small offices, personal labs, and testing environments often use this approach. It avoids false alarms, keeps storage usage under control, and gives the operator full authority over what gets recorded.

MANUAL CCTV CODE:

 

You can download the project folder along with other resources from my Patreon Page.

MANUAL CCTV – HOW THE CODE WORKS

In the code, the YOLOv5 model is first loaded using the RDK X5 DNN library. This model is optimized to run on the BPU, which is why the input format must be NV12 instead of normal BGR. The USB camera provides BGR frames, so the image is converted into NV12 format before inference. This step is very important because it allows hardware-accelerated AI processing instead of slow CPU-based inference.

Once inference is complete, the post-processing extracts only the required object, which in this case is a person. Bounding boxes are drawn, and a CCTV-style timestamp is added to the video frame. When I press the R key, the system starts recording, and when I press it again, the recording stops and the video is saved with a timestamped filename. This is exactly how a real CCTV recorder behaves.

MANUAL CCTV – PRACTICAL DEMO

Now let me show you the manual CCTV system in action. As you can see, the live feed is running continuously, and AI is detecting people in real time.



The bounding boxes appear immediately, and the timestamp is always visible on the screen.

When I press the R key, recording starts instantly.

You can see the recording indicator on the screen, and the video is being saved frame by frame.

When I press R again, the recording stops, and the file is saved.

This gives full control to the user and is perfect for environments where manual supervision is required. Manual CCTV systems are good, but modern surveillance systems are moving toward automation.

AUTOMATIC CCTV SYSTEM – OVERVIEW

In the automatic CCTV system, I am using a MIPI camera instead of a USB camera.



MIPI cameras provide lower latency, better synchronization, and are more suitable for embedded AI systems.

This system does not wait for me to press any button. Instead, it uses AI, logic, and time-based decision-making to automatically start recording when a specific condition is met.

AUTOMATIC CCTV CODE:




 

Although the core source code is shared in this article, additional supporting files are required to successfully build and run the project. These include configuration files, and platform-specific dependencies for the RDK X5 environment. To make things easier and avoid setup issues, the complete project folder is available for download on my Patreon page, where everything is already organized and ready to run. It’s just a 1$ subscription and you get access to all my projects.

AUTOMATIC CCTV – CODE EXPLANATION:

Now let’s understand how this works in the code.

First, the AI model is loaded exactly the same way as in the previous demo using the RDK X5 DNN library.

The YOLOv5 model runs on the BPU, so the input frames must be in NV12 format before inference can happen. Since the MIPI camera already outputs NV12 data, there is no need for additional color conversion. This makes the pipeline faster, more efficient, and much better suited for real-time AI processing compared to a USB camera.

Once inference is completed, the code moves into the post-processing stage. Here, all detected objects are extracted from the model output, including their class IDs, confidence values, and bounding box coordinates.

Next, the system applies a filtering rule based on the selected object class. In this demo, the target class is set to person, so only detections belonging to the “person” category are processed further. All other detected objects are ignored. If you want, you can easily change this to any object available in the COCO class list, or modify the logic to allow multiple object types at the same time.

This clear separation between inference, post-processing, and filtering makes the code easy to understand, modify, and extend for real-world surveillance applications.

PRACTICAL DEMO:

Now let me show you how all of this works in real time.



First, I define a region of interest on the screen. Using the mouse, I can draw any shape I want; a rectangle, a triangle, or even a custom polygon.

This tells the AI exactly where it should monitor activity. In real-world surveillance, this is critical. You usually care about specific areas like doors, windows, or restricted zones, not the entire camera view.

Next comes smart object-based detection. The system doesn’t record everything it sees.

It only looks for specific objects. In this demo, I am detecting a person, but the same logic can be applied to other objects, or even multiple object types at the same time.

To make detection more accurate, the system doesn’t check the full bounding box. Instead, it checks a very precise point; the bottom center of the box, which represents where the feet touch the ground.



This means a person is only detected when they actually step inside the region.

Just passing near the boundary doesn’t trigger anything, which greatly reduces false alarms.

Now, real environments aren’t perfect.

Detections can flicker because of lighting changes or occlusion. That’s why the system includes glitch protection. If a person disappears for a split second, the system doesn’t immediately reset. It waits and confirms the detection is stable, making it reliable for real-world use.

Even after detection, recording doesn’t start immediately.

The system uses time-based logic. The person must stay inside the region for a predefined duration. This filters out people who are just walking past and focuses only on meaningful activity.

Once all the conditions are met, the system works completely automatically. When a person enters the defined region, the system starts counting time in the background. If the person stays inside the area for the required duration, the event is confirmed and video recording starts on its own.

There are no buttons, no manual control; everything is handled by AI and logic.

For those who want to go deeper, I have shared the complete project folders on my Patreon. Everything is ready to run, so you can focus on learning instead of setup.

At the same time, the system provides clear hardware feedback using an LED connected to a GPIO pin. When the object enters the region, the LED starts blinking, indicating that detection is active and the timer is running.



Once the time threshold is reached, the LED stops blinking and turns solid, showing that recording has started.

This kind of hardware feedback is extremely useful in embedded systems, especially when a display is not available. With just an LED, you can instantly understand the system state; exactly how professional systems behave.

So, that’s all for now.

Support me on Patreon:

If you enjoy my work and find these projects helpful, please consider supporting me on Patreon. With just $1, you can get access to all project source codes, schematics, and extra resources that I share with my supporters. Your support helps me continue creating new electronics tutorials, experiments, and open projects for the community. Thank you so much for being part of this journey and for supporting my work!

Watch Video Tutorial:

This CCTV Ignores You... Unless You're a Threat (RDK X5 AI)


Discover more from Electronic Clinic

Subscribe to get the latest posts sent to your email.

Engr. Shahzada Fahad

Engr. Shahzada Fahad is an Electrical Engineer with over 15 years of hands-on experience in electronics design, programming, and PCB development. He specializes in microcontrollers (Arduino, ESP32, STM32, Raspberry Pi), robotics, and IoT systems. He is the founder and lead author at Electronic Clinic, dedicated to sharing practical knowledge.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button

Discover more from Electronic Clinic

Subscribe now to keep reading and get access to the full archive.

Continue reading

Electronic Clinic
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.