LoginSignup
0
0

More than 3 years have passed since last update.

サーマルカメラ(サーモ AI デバイス TiD) Python OpenCV編

Last updated at Posted at 2021-01-10

Raspberry Pi上のPythonでOpenCVを使用して、人検出を行います。


  1. 紹介編
  2. センサ編
  3. センサケース編
  4. Raspberry Pi編
  5. Python編
    5.1 Form編
    5.2 オムロン 非接触温度センサ D6T-44L-06編
    5.3 Pololu 測距センサ VL53L0X編
    5.4 BOSCH 温湿度・気圧センサ BME280
    5.5 シャットダウン・再起動スイッチ編
    5.6 OpenCV編
    5.7 高速化編

OpenCVの準備

OpenCVモジュールがインストールされていない場合、下記コマンドでインストールしてください。

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

import時にエラーが出たら4.1.1.26から4.1.0.25へバージョンダウン

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

Pillowの準備

Pillowモジュールがインストールされていない場合、下記コマンドでインストールしてください。

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

下記のエラーが出たら

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

顔検出

顔を検出してみます。

detected.jpg
detect.py と haarcascade_frontalface_default.xml(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: サーマルカメラ(サーモ AI デバイス TiD) Python編
web: サーモ AI デバイス TiD Python OpenCV編 (URLが変更されました)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0