0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

不在時にはひまじんでなければ(顔認証、顔検知)、Lineに通知するを実装 ステップ

Last updated at Posted at 2025-01-04

現在の不在時に本人以外の場合にLine通知する機能を追加してみる。 9:30-11:30 ジム休みの日など、不在じゃないときあるので、実装していく。 

1.ひまじんの画像を/home/pi/me.jpg で格納。正面でとりました。
参考サイトを参考にPythonを記述
参考サイト
https://blog.grasys.io/post/uema/python-face-recognition/
以下 kao_ninsyou.pyで保存&実行

import sys
import cv2
import face_recognition
from picamera2 import Picamera2

# カメラの設定
camera = Picamera2()
camera.configure(camera.create_preview_configuration(main={
        "format": 'XRGB8888',
        "size": (640, 480)
}))
camera.start()

# 画像を読み込み、顔の特徴値を取得する
uema_image = face_recognition.load_image_file("/home/pi/me.jpg")
uema_face_encoding = face_recognition.face_encodings(uema_image)[0]

face_locations = []
face_encodings = []

print("Start capture image")

while True:
    # カメラからイメージを撮る
    image = camera.capture_array()
    output = cv2.cvtColor(image, cv2.COLOR_BGRA2BGR)

    # 顔を検知する
    face_locations = face_recognition.face_locations(output)
    print(f"Found {len(face_locations)} faces")
    face_encodings = face_recognition.face_encodings(output, face_locations)

    for face_encoding in face_encodings:
        # 読み込んだ顔の特徴量とカメラから取得した顔の特徴量を比較する
        match = face_recognition.compare_faces([uema_face_encoding], face_encoding)

        if match[0]:
            print("顔です。!")
            # プログラムを終了する
            sys.exit(0)

4.実行結果
顔は認証できてますね。picamera2 でも同じことができそうですね。

[4:22:16.837596510] [3271]  INFO Camera camera_manager.cpp:297 libcamera v0.0.5+83-bde9b04f
[4:22:16.995994680] [3277]  INFO RPI vc4.cpp:437 Registered camera /base/soc/i2c0mux/i2c@1/imx708@1a to Unicam device /dev/media3 and ISP device /dev/media0
[4:22:16.996660769] [3277]  INFO RPI pipeline_base.cpp:1101 Using configuration file '/usr/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml'
[4:22:17.016900278] [3271]  INFO Camera camera.cpp:1033 configuring streams: (0) 640x480-XRGB8888 (1) 1536x864-SBGGR10_CSI2P
[4:22:17.018282456] [3277]  INFO RPI vc4.cpp:565 Sensor: /base/soc/i2c0mux/i2c@1/imx708@1a - Selected sensor format: 1536x864-SBGGR10_1X10 - Selected unicam format: 1536x864-pBAA
Start capture image
Found 1 faces
顔です。!

5.今度はひまじんを検出させてみる。
ちょっと時間かかりそう。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?