Thermal Camera (Thermo AI Device TiD) Python OpenCV Edition

Use OpenCV in Python on Raspberry Pi to detect people.


  1. Introduction
  2. Sensor
  3. Sensor case
  4. Raspberry Pi
  5. Python 5.1 Form 5.2 OMRON Non-contact Temperature Sensor D6T-44L-06 5.3 Pololu ranging sensor VL53L0X edition 5.4 BOSCH Temperature / Humidity / Barometric Pressure Sensor BME280 5.5 Shutdown / Reboot Switch Edition 5.6 OpenCV 5.7 Speedup

OpenCV preparation

If the OpenCV module is not installed, install it with the following command.

sudo apt update
sudo apt upgrade -y
sudo apt install python3-pip -y
sudo pip3 --default-timeout=1000 install opencv-contrib-python

sudo apt-get install libhdf5-dev libhdf5-serial-dev libatlas-base-dev libjasper-dev  libqtgui4 libqt4-test libgstreamer1.0-0 libwebp-dev libilmbase-dev libopenexr-dev libavcodec-dev libavformat-dev libswscale-dev libharfbuzz-dev

If an error occurs during import, downgrade from 4.1.1.26 to 4.1.0.25

sudo pip3 install opencv-python==4.1.0.25
sudo pip3 install opencv-contrib-python==4.1.0.25

Pillow preparation

If the Pillow module is not installed, install it with the following command.

sudo apt-get update
sudo apt-get install libjpeg-dev -y
sudo apt-get install zlib1g-dev -y
sudo apt-get install libfreetype6-dev -y
sudo apt-get install liblcms1-dev -y
sudo apt-get install libopenjp2-7 -y
sudo apt-get install libtiff5 -y
sudo pip install Pillow

If you get the following error

from PIL import Image, ImageTk
ImportError: cannot import name 'ImageTk' from 'PIL' (/usr/lib/python3/dist-packages/PIL/__init__.py)
sudo apt-get install python3-pil.imaget

Face detection

I will try to detect the face.

detected.jpg detect.py and haarcascade_frontalface_default.xml (compressed with ZIP)

import os
import cv2

os.chdir(os.path.dirname(os.path.abspath(__file__)))

face_cascade_path = 'haarcascade_frontalface_default.xml'

face_cascade = cv2.CascadeClassifier(face_cascade_path)

cap = cv2.VideoCapture(0)

while True:
    ret, img = cap.read()
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    faces = face_cascade.detectMultiScale(gray, scaleFactor=1.3, minNeighbors=5)
    for x, y, w, h in faces:
        cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
        face = img[y: y + h, x: x + w]
        face_gray = gray[y: y + h, x: x + w]
    cv2.imshow('video image', img)

    key = cv2.waitKey(10)

    if key == 27:
        break

cap.release()
cv2.destroyAllWindows()

YouTube: Thermal Camera (Thermo AI Device TiD) Python Edition web: Thermo AI device TiD Python OpenCV (URL is subject to change.)

Recommended Posts

Thermal Camera (Thermo AI Device TiD) Python OpenCV Edition
Thermal camera (thermo AI device TiD) Python VL53L0X edition
Thermal Camera (Thermo AI Device TiD) Python D6T-44L-06 Edition
Thermal Camera (Thermo AI Device TiD) Python Form
Thermal Camera (Thermo AI Device TiD) Python Acceleration
Thermal camera (Thermo AI device TiD) Sensor edition
Thermal camera (Thermo AI device TiD) Python BME280
Thermal Camera (Thermo AI Device TiD) Raspberry Pi Edition
Thermal Camera (Thermo AI Device TiD) Introduction
Camera capture with Python + OpenCV
Face recognition with camera with opencv3 + python2.7
Raspberry Pi Security Infrared Camera (Python Edition)
Image acquisition from camera with Python + OpenCV