fbpx
Sigmoidal
  • Home
  • LinkedIn
  • About me
  • Contact
No Result
View All Result
  • Português
  • Home
  • LinkedIn
  • About me
  • Contact
No Result
View All Result
Sigmoidal
No Result
View All Result

Build a Surveillance System with Computer Vision and Deep Learning

Carlos Melo by Carlos Melo
March 23, 2023
in Computer Vision
1
140
SHARES
4.7k
VIEWS
Share on LinkedInShare on FacebookShare on Whatsapp

Ever thought about creating an aerial surveillance system using a drone purchased on eBay, a notebook, and Deep Learning techniques applied to Computer Vision problems?

Inspired by the work of Dr. Adrian Rosebrock, I developed this innovative project to combine drone technology and Computer Vision techniques with Deep Learning to create an aerial surveillance system.

In this YouTube video, I want to show you not only how I implemented this architecture, but also demonstrate the project in action. And what better way to do that than with some flights within a Air Force Base?

Watch the video above to learn how I trained a deep neural network in TensorFlow and built a pipeline capable of detecting objects from real-time video streamed by a drone in flight.

What are the applications of computer vision in drones

A drone is an unmanned aerial vehicle (UAV) remotely controlled, which can be used for various purposes, such as defense, security, leisure, and even delivery of goods. The fact is, as options on the market become increasingly affordable, the range of possible applications expands.

Wedding filming, celebrity sightings by paparazzi, high voltage line maintenance, aerial surveillance, and purely recreational flights (the famous “flying for the pleasure of flying”) are just a few examples of the many applications for drones.

Since I was a pilot and had a brand-new drone to test, I thought, ‘Why not use Deep Learning to implement a practical case?’

These devices are gaining importance due to their characteristics: low mass (made from low-density materials), small size (easy access to many environments), long-range, and especially, high autonomy. 

Specifically, some of the thousands of hours of my operational flying life were spent on alert missions in certain locations, such as Natal Air Base (BANT), Barreira do Inferno Launch Center (CLBI), Alcantara Launch Center (CLA), Brigadeiro Velloso Test Field, and the Air Force Academy (AFA). Since these are restricted areas, this type of mission aimed to verify if there were unauthorized people in those locations.

As a Major Aviator of the Reserve and pilot of the Brazilian Air Force for 16 years, I have carried out several missions known as Aerial Surveillance.

I don’t know if you’re aware, but the cost of operating a military aircraft per flight hour is extremely high. If you add to that equation all the professionals involved, the size of the areas to be monitored, and the number of missions that the Brazilian Air Force must constantly fulfill, it’s easy to understand my motivation for developing a solution based on commercial drones.

DJI Mavic Air 2 Specifications

The drone model I own is the DJI Mavic Air 2, a fantastic piece of equipment to fly. Weighing just 570 grams, the Mavic Air 2 can fly for up to 34 minutes, reach over 18 kilometers in distance, and has a maximum flight ceiling (maximum altitude) of 5,000 meters.

Additionally, it can reach speeds of nearly 70 km/h under ideal conditions, record videos at 4K resolution (using internal memory or a memory card), and is capable of streaming video at 720p quality at 30 fps (frames per second).

Another fantastic feature of this model is the ability to attach your smartphone to the controller (joystick) and receive flight information directly on your screen.

Project Overview

The data pipeline, applications, and architecture choices were made based on the equipment I had available at that time. If you want to replicate the project, I recommend researching whether they would also be the most suitable options for you.

For example, I know there are drones capable of transmitting images directly to the computer without using a smartphone as an intermediary.

Equipment used to operate the aerial surveillance system in any location.

To solve this problem, since the images from the drone’s camera were displayed on my smartphone screen while I was piloting, I installed the “Prism Live Studio” app (available for free on iPhone and Android). With this app, I was able to stream my phone’s screen (using the RTMP protocol) to the computer.

Before anything else, I needed all devices to be connected to the same network, with local IP addresses assigned to each of them. This was easy, as I simply created a hotspot from my smartphone and connected my MacBook to that Wi-Fi network.

However, just because all devices are connected to the same network doesn’t mean you can access each of them. To receive the transmission from my smartphone’s screen, I installed NGINX on my MacBook using Homebrew (a package manager for Mac, similar to APT or YUM for Linux), which allowed me to create an RTMP server on the machine.

Implementing YOLO with TensorFlow

The architecture used for the project was the well-known YOLO, trained on the COCO dataset. Depending on your application, you can choose whether to keep all possible classes or select only some of them (cars, people, motorcycles, etc.).

The first part of the code imports the packages used in the object detector (based on the TensorFlow API) and defines constants related to the model’s sensitivity.

# REFERÊNCIAS
#
# Implementação da arquitetura YOLO baseada no artigo YOLO object detection with OpenCV
# do Adrian Rosebrock, autor do livro Deep Learning for Computer Vision


# importar os pacotes necessários
import numpy as np
import argparse
import os
import cv2
import time
from imutils.video import VideoStream
from imutils.video import FPS


# constantes do modelo
CONFIDENCE_MIN = 0.4
NMS_THRESHOLD = 0.2
MODEL_BASE_PATH = "yolo-coco"

# receber os argumentos para o script
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--input", required=True, help="Endereço do streaming do drone")
streaming_path = vars(ap.parse_args())['input']

Since we are looking for real-time processing of the streaming video, and not loading a static file of some video, we import the VideoStream e FPS objects from the fantastic imutils library.

After execution, the script will load the trained YOLO model, with its weights and configurations passed within the yolov3.cfg file, the defined names (labels), and extract the unconnected layers of the architecture.

# extrair os nomes das classes a partir do arquivo
print("[+] Carregando labels das classes treinadas...")
with open(os.path.sep.join([MODEL_BASE_PATH, 'coco.names'])) as f:
    labels = f.read().strip().split("\n")

    # gerar cores únicas para cada label
    np.random.seed(42)
    colors = np.random.randint(0, 255, size=(len(labels), 3), dtype="uint8")

# carregar o modelo treinado YOLO (c/ COCO dataset)
print("[+] Carregando o modelo YOLO treinado no COCO dataset...")
net = cv2.dnn.readNetFromDarknet(
    os.path.sep.join([MODEL_BASE_PATH, 'yolov3.cfg']),
    os.path.sep.join([MODEL_BASE_PATH, 'yolov3.weights']))

# extrair layers não conectados da arquitetura YOLO
ln = net.getLayerNames()
ln = [ln[i[0] - 1] for i in net.getUnconnectedOutLayers()]

After run, the script will load the trained YOLO model, with its weights and configurations passed within the yolov3.cfg file, the defined names (labels), and extract the unconnected layers of the architecture.

Please note that in my Github repository, containing the complete code, I did not provide the model due to its size. However, as you can see, you can download it by calling the cv2.dnn.readNetFromDarknet() method.

If you have already implemented a Deep Learning model for classification from local files, you probably manipulated each of the frames loaded by OpenCV. In practice, this means that a video with a 30 fps rate has 30 images per second, and all of them will pass through the neurons of the model.

However, when we are looking for real-time analysis, we probably won’t be able to keep up with that frame rate without powerful equipment. It’s a trade-off, of course, where we will sacrifice the fps rate to gain agility.

# iniciar a recepção do streaming
vs = VideoStream(streaming_path).start()
time.sleep(1)
fps = FPS().start()
print("[+] Iniciando a recepção do streaming via RTMP...")

To achieve this processing, we instantiate a VideoStream(streaming_path) object, with the passed argument being the drone’s address via the RTMP protocol.

Once we are acquiring the frames from the provided network address, we simply iterate through them. Depending on the machine you have, you may achieve a higher or lower fps rate.

# iterar sobre os frames do streaming
while True:
    frame = vs.read()

    # caso se deseje redimensionar os frames
    # frame = cv2.resize(frame, None, fx=0.2, fy=0.2)

    # capturar a largura e altura do frame
    (H, W) = frame.shape[:2]

    # construir um container blob e fazer uma passagem (forward) na YOLO
    blob = cv2.dnn.blobFromImage(frame, 1 / 255.0, (416, 416), swapRB=True, crop=False)
    net.setInput(blob)
    layer_outputs = net.forward(ln)

    # criar listas com boxes, nível de confiança e ids das classes
    boxes = []
    confidences = []
    class_ids = []

    for output in layer_outputs:
        for detection in output:
            scores = detection[5:]
            class_id = np.argmax(scores)
            confidence = scores[class_id]

            # filtrar pelo threshold da confiança
            if confidence > CONFIDENCE_MIN and class_id in [0, 1, 2, 3]:
                box = detection[0:4] * np.array([W, H, W, H])
                (center_x, center_y, width, height) = box.astype("int")

                x = int(center_x - (width / 2))
                y = int(center_y - (height / 2))

                boxes.append([x, y, int(width), int(height)])
                confidences.append(float(confidence))
                class_ids.append(class_id)

In summary and within what is possible to explain in a blog article, the code above identifies the dimensions of the transmitted frames, constructs a “blob container,” and performs a forward pass through the YOLO already loaded with weights trained on the COCO dataset.

To store the possible detections, lists are created to store the coordinates of the rectangles, the prediction confidence, and the class identifiers associated with each of the predictions.

    # eliminar ruído e redundâncias aplicando non-maxima suppression
    new_ids = cv2.dnn.NMSBoxes(boxes, confidences,CONFIDENCE_MIN, NMS_THRESHOLD)
    if len(new_ids) > 0:
        for i in new_ids.flatten():
            (x, y) = (boxes[i][0], boxes[i][1])
            (w, h) = (boxes[i][2], boxes[i][3])

            # plotar retângulo e texto das classes detectadas no frame atual
            color_picked = [int(c) for c in colors[class_ids[i]]]
            cv2.rectangle(frame, (x, y), (x + w, y + h), color_picked, 2)
            text = "{}: {:.4f}".format(labels[class_ids[i]], confidences[i])
            cv2.putText(frame, text, (x, y - 5), cv2.FONT_HERSHEY_SIMPLEX, 0.5, color_picked, 2)

    # exibir o frame atual
    cv2.imshow('frame', frame)

    # sair, caso seja pressionada a tecla ESC
    c = cv2.waitKey(1)
    if c == 27:
        break

    # atualiza o fps
    fps.update()



# eliminar processos e janelas
fps.stop()
cv2.destroyAllWindows()
vs.stop()

In this last part, I try to eliminate noise and redundancies with a suitable filter and draw a rectangle for each prediction that is above the CONFIDENCE_MIN, NMS_THRESHOLD thresholds.

As long as the user doesn’t cancel the processing, our script will continue to iterate through the frames being transmitted by the drone.

Trained model, authorized takeoff!

With the trained model loaded, don’t forget to start the NGINX-based server (if it’s not active by default).

You’ll also need the address of your smartphone on the network to provide as an argument when running the script (remember that since my drone doesn’t have the capability to transmit directly over the network, we’re capturing the drone’s view from the smartphone’s screen).

Trained model, authorized takeoff!

After starting to monitor port 1935 and capturing RTMP packets with OpenCV, the frames will start passing through YOLO, and you’ll see the first objects appear on the screen, with their corresponding bounding boxes.

Caso você deseje, o código-fonte está disponível nesse meu repositório do Github.

Summary

Recapping the main steps of the project, we followed the sequence described below:

  1. Created a hotspot from the smartphone and connected my laptop to it, same network.
  2. Installed NGINX on the laptop to create an RTMP Server.
  3. Streamed the smartphone’s screen to the laptop using the PRISM Live mobile app.
  4. Ran a Python script to monitor port 1935 and capture RTMP packets with OpenCV.
  5. Processed the frames using the deep learning YOLO architecture, trained on the COCO dataset.

In this innovative project, I combined drone technology and Computer Vision techniques with Deep Learning to create an aerial surveillance system. The project involved streaming real-time video from a DJI Mavic Air 2 drone to a laptop, where a YOLO-based object detection model was applied to identify objects in the video feed.

This aerial surveillance system has the potential to significantly reduce the cost of monitoring large areas, as compared to using manned aircraft for the same purpose. If you’re interested, the source code is available in my Github repository.

Share10Share56Send
Previous Post

Fundamentals of Image Formation

Next Post

Matrix Transformations and Coordinate Systems with Python

Carlos Melo

Carlos Melo

Computer Vision Engineer with a degree in Aeronautical Sciences from the Air Force Academy (AFA), Master in Aerospace Engineering from the Technological Institute of Aeronautics (ITA), and founder of Sigmoidal.

Related Posts

Blog

What is Sampling and Quantization in Image Processing

by Carlos Melo
June 20, 2025
Como equalizar histograma de imagens com OpenCV e Python
Computer Vision

Histogram Equalization with OpenCV and Python

by Carlos Melo
July 16, 2024
How to Train YOLOv9 on Custom Dataset
Computer Vision

How to Train YOLOv9 on Custom Dataset – A Complete Tutorial

by Carlos Melo
February 29, 2024
YOLOv9 para detecção de Objetos
Blog

YOLOv9: A Step-by-Step Tutorial for Object Detection

by Carlos Melo
February 26, 2024
Depth Anything - Estimativa de Profundidade Monocular
Computer Vision

Depth Estimation on Single Camera with Depth Anything

by Carlos Melo
February 23, 2024
Next Post
Matrix Transformations and Coordinate Systems with Python

Matrix Transformations and Coordinate Systems with Python

Comments 1

  1. Vunana Pedro says:
    2 years ago

    Muito bom e bem necessário

    Reply

Leave a Reply Cancel reply

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

  • Trending
  • Comments
  • Latest
Estimativa de Pose Humana com MediaPipe

Real-time Human Pose Estimation using MediaPipe

September 11, 2023
ORB-SLAM 3: A Tool for 3D Mapping and Localization

ORB-SLAM 3: A Tool for 3D Mapping and Localization

April 10, 2023

Build a Surveillance System with Computer Vision and Deep Learning

1
ORB-SLAM 3: A Tool for 3D Mapping and Localization

ORB-SLAM 3: A Tool for 3D Mapping and Localization

1
Point Cloud Processing with Open3D and Python

Point Cloud Processing with Open3D and Python

1

Fundamentals of Image Formation

0

What is Sampling and Quantization in Image Processing

June 20, 2025
Como equalizar histograma de imagens com OpenCV e Python

Histogram Equalization with OpenCV and Python

July 16, 2024
How to Train YOLOv9 on Custom Dataset

How to Train YOLOv9 on Custom Dataset – A Complete Tutorial

February 29, 2024
YOLOv9 para detecção de Objetos

YOLOv9: A Step-by-Step Tutorial for Object Detection

February 26, 2024

Seguir

  • Aqui nós 🇺🇸, a placa é sua. Quando você troca o carro,  por exemplo, você mesmo tira a sua placa do carro vendido e instala a parafusa no carro novo.

Por exemplo, hoje eu vi aqui no “Detran” dos Estados Unidos, paguei a trasnferência do title do veículo, e já comprei minha primeira placa. 

Tudo muito fácil e rápido. Foi menos de 1 hora para resolver toda a burocracia! #usa🇺🇸 #usa
  • Como um carro autônomo "enxerga" o mundo ao redor?

Não há olhos nem intuição, apenas sensores e matemática. Cada imagem capturada passa por um processo rigoroso: amostragem espacial, quantização de intensidade e codificação digital. 

Esse é o desafio, representar um objeto 3D do mundo real, em pixels que façam sentido para a Inteligência Artificial.

🚗📷 A visão computacional é a área mais inovadora do mundo!

Comente aqui se você concorda.

#carrosautonomos #inteligenciaartificial #IA #visãocomputacional
  • 👁️🤖Visão Computacional: a área mais inovadora do mundo! Clique no link da bio e se inscreva na PÓS EM VISÃO COMPUTACIONAL E DEEP LEARNING! #machinelearning #datascience #visãocomputacional
  • E aí, Sergião @spacetoday Você tem DADO em casa? 😂😂

A pergunta pode ter ficado sem resposta no dia. Mas afinal, o que são “dados”?

No mundo de Data Science, dados são apenas registros brutos. Números, textos, cliques, sensores, imagens. Sozinhos, eles não dizem nada 

Mas quando aplicamos técnicas de Data Science, esses dados ganham significado. Viram informação.

E quando a informação é bem interpretada, ela se transforma em conhecimento. Conhecimento gera vantagem estratégica 🎲

Hoje, Data Science não é mais opcional. É essencial para qualquer empresa que quer competir de verdade.

#datascience #cientistadedados #machinelearning
  • 🎙️ Corte da minha conversa com o Thiago Nigro, no PrimoCast #224

Falamos sobre por que os dados são considerados o novo petróleo - para mim, dados são o novo bacon!

Expliquei como empresas que dominam a ciência de dados ganham vantagem real no mercado. Não por armazenarem mais dados, mas por saberem o que fazer com eles.

Também conversamos sobre as oportunidades para quem quer entrar na área de tecnologia. Data Science é uma das áreas mais democráticas que existem. Não importa sua idade, formação ou cidade. O que importa é a vontade de aprender.

Se você quiser ver o episódio completo, é só buscar por Primocast 224.

“O que diferencia uma organização de outra não é a capacidade de armazenamento de dados; é a capacidade de seu pessoal extrair conhecimento desses dados.”

#machinelearning #datascience #visãocomputacional #python
  • 📸 Palestra que realizei no palco principal da Campus Party #15, o maior evento de tecnologia da América Latina!

O tema que escolhi foi "Computação Espacial", onde destaquei as inovações no uso de visão computacional para reconstrução 3D e navegação autônoma.

Apresentei técnicas como Structure-from-Motion (SFM), uma técnica capaz de reconstruir cidades inteiras (como Roma) usando apenas fotos publicadas em redes sociais, e ORB-SLAM, usada por drones e robôs para mapeamento em tempo real.

#visãocomputacional #machinelearning #datascience #python
  • ⚠️❗ Não deem ideia para o Haddad! 

A França usou Inteligência Artificial para detectar mais de 20 mil piscinas não declaradas a partir de imagens aéreas.

Com modelos de Deep Learning, o governo identificou quem estava devendo imposto... e arrecadou mais de €10 milhões com isso.

Quer saber como foi feito? Veja no post completo no blog do Sigmoidal: https://sigmoidal.ai/como-a-franca-usou-inteligencia-artificial-para-detectar-20-mil-piscinas/

#datascience #deeplearning #computerVision #IA
  • Como aprender QUALQUER coisa rapidamente?

💡 Comece com projetos reais desde o primeiro dia.
📁 Crie um portfólio enquanto aprende. 
📢 E compartilhe! Poste, escreva, ensine. Mostre o que está fazendo. Documente a jornada, não o resultado.

Dois livros que mudaram meu jogo:
-> Ultra Aprendizado (Scott Young)
-> Uma Vida Intelectual (Sertillanges)

Aprenda em público. Evolua fazendo.

#ultralearning #estudos #carreira
  • Como eu usava VISÃO COMPUTACIONAL no Centro de Operações Espaciais, planejando missões de satélites em situações de desastres naturais.

A visão computacional é uma fronteira fascinante da tecnologia que transforma a forma como entendemos e respondemos a desastres e situações críticas. 

Neste vídeo, eu compartilho um pouco da minha experiência como Engenheiro de Missão de Satélite e especialista em Visão Computacional. 

#VisãoComputacional #DataScience #MachineLearning #Python
  • 🤔 Essa é a MELHOR linguagem de programação, afinal?

Coloque sua opinião nos comentários!

#python #datascience #machinelearning
  • 💘 A história de como conquistei minha esposa... com Python!

Lá em 2011, mandei a real:

“Eu programo em Python.”
O resto é história.
  • Para rotacionar uma matriz 2D em 90°, primeiro inverto a ordem das linhas (reverse). Depois, faço a transposição in-place. Isso troca matrix[i][j] com matrix[j][i], sem criar outra matriz. A complexidade segue sendo O(n²), mas o uso de memória se mantém O(1).

Esse padrão aparece com frequência em entrevistas. Entender bem reverse + transpose te prepara para várias variações em matrizes.

#machinelearning #visaocomputacional #leetcode
  • Na última aula de estrutura de dados, rodei um simulador de labirintos para ensinar como resolver problemas em grids e matrizes.

Mostrei na prática a diferença entre DFS e BFS. Enquanto a DFS usa stacks, a BFS utiliza a estrutura de fila (queue). Cada abordagem tem seu padrão de propagação e uso ideal.

#machinelearning #visaocomputacional #algoritmos
  • 🔴 Live #2 – Matrizes e Grids: Fundamentos e Algoritmos Essenciais

Na segunda aula da série de lives sobre Estruturas de Dados e Algoritmos, o foco será em Matrizes e Grids, estruturas fundamentais em problemas de caminho, busca e representação de dados espaciais.

📌 O que você vai ver:

Fundamentos de matrizes e grids em programação
Algoritmos de busca: DFS e BFS aplicados a grids
Resolução ao vivo de problemas do LeetCode

📅 Terça-feira, 01/07, às 22h no YouTube 
🎥 (link nos Stories)

#algoritmos #estruturasdedados #leetcode #datascience #machinelearning
  • 💡 Quer passar em entrevistas técnicas?
Veja essa estratégia para você estudar estruturas de dados em uma sequência lógica e intuitiva.
⠀
👨‍🏫 NEETCODE.io
⠀
🚀 Marque alguém que também está se preparando!

#EntrevistaTecnica #LeetCode #MachineLearning #Data Science
  • Live #1 – Arrays & Strings: Teoria e Prática para Entrevistas Técnicas

Segunda-feira eu irei começar uma série de lives sobre Estruturas de Dados e Algoritmos. 

No primeiro encontro, falarei sobre um dos tipos de problemas mais cobrados em entrevistas: Arrays e Strings.

Nesta aula, você vai entender a teoria por trás dessas estruturas, aprender os principais padrões de resolução de problemas e aplicar esse conhecimento em exercícios selecionados do LeetCode.

📅 Segunda-feira, 23/06, às 21h no YouTube

🎥 (link nos Stories)

#machinelearning #datascience #cienciadedados #visãocomputacional
Instagram Youtube LinkedIn Twitter
Sigmoidal

O melhor conteúdo técnico de Data Science, com projetos práticos e exemplos do mundo real.

Seguir no Instagram

Categories

  • Aerospace Engineering
  • Blog
  • Carreira
  • Computer Vision
  • Data Science
  • Deep Learning
  • Featured
  • Iniciantes
  • Machine Learning
  • Posts

Navegar por Tags

3d 3d machine learning 3d vision apollo 13 bayer filter camera calibration career cientista de dados clahe computer vision custom dataset data science deep learning depth anything depth estimation detecção de objetos digital image processing histogram histogram equalization image formation job lens lente machine learning machine learning engineering nasa object detection open3d opencv pinhole projeto python quantization redes neurais roboflow rocket salário sampling scikit-learn space tensorflow tutorial visão computacional yolov8 yolov9

© 2024 Sigmoidal - Aprenda Data Science, Visão Computacional e Python na prática.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In

Add New Playlist

No Result
View All Result
  • Home
  • Cursos
  • Pós-Graduação
  • Blog
  • Sobre Mim
  • Contato
  • Português

© 2024 Sigmoidal - Aprenda Data Science, Visão Computacional e Python na prática.