KeioTeamWolveZ / wolvez2023-soft

4 stars 0 forks source link

オートフォーカスカメラ #20

Closed masato1004 closed 1 year ago

masato1004 commented 1 year ago

オートフォーカス機能付きラズパイカメラ

従来使用していたラズパイカメラと同じ方法では使用できないっぽいので,使えるようになるまでの検討段階をまとめていきます.

使用ラズパイカメ

16MP IMX519 image

現段階での課題点

19238901 commented 1 year ago

#オートフォーカスカメラ実装のブログ https://docs.arducam.com/Raspberry-Pi-Camera/Native-camera/Quick-Start-Guide/

19238901 commented 1 year ago

OpenCVインストール手順 ※pythonのバージョンに合わせる https://python-academia.com/raspberrypi-opencv/

masato1004 commented 1 year ago

Use libcamera in python code

shuld be imported libcamera library in python code...?

19238901 commented 1 year ago

Usage of Picamera2

#!/usr/bin/python3
import time

import cv2

from picamera2 import MappedArray, Picamera2, Preview

# This version creates a lores YUV stream, extracts the Y channel and runs the face
# detector directly on that. We use the supplied OpenGL accelerated preview window
# and delegate the face box drawing to its callback function, thereby running the
# preview at the full rate with face updates as and when they are ready.

face_detector = cv2.CascadeClassifier("/usr/share/opencv4/haarcascades/haarcascade_frontalface_default.xml")

def draw_faces(request):
    with MappedArray(request, "main") as m:
        for f in faces:
            (x, y, w, h) = [c * n // d for c, n, d in zip(f, (w0, h0) * 2, (w1, h1) * 2)]
            cv2.rectangle(m.array, (x, y), (x + w, y + h), (0, 255, 0, 0))

picam2 = Picamera2()
picam2.start_preview(Preview.QTGL)
config = picam2.create_preview_configuration(main={"size": (640, 480)},
                                             lores={"size": (320, 240), "format": "YUV420"})
picam2.configure(config)

(w0, h0) = picam2.stream_configuration("main")["size"]
(w1, h1) = picam2.stream_configuration("lores")["size"]
s1 = picam2.stream_configuration("lores")["stride"]
faces = []
picam2.post_callback = draw_faces

picam2.start()

start_time = time.monotonic()
# Run for 10 seconds so that we can include this example in the test suite.
while time.monotonic() - start_time < 10:
    buffer = picam2.capture_buffer("lores")
    grey = buffer[:s1 * h1].reshape((h1, s1))
    faces = face_detector.detectMultiScale(grey, 1.1, 3)
19238901 commented 1 year ago

サンプルコード

masato1004 commented 1 year ago

方針

一旦旧OSを使用しても動作できるよう再開発

19238901 commented 1 year ago

旧OSでAFカメラを使用できる? Arducamの高解像度カメラを使う

19238901 commented 1 year ago
import cv2
from datetime import datetime

# /dev/video0を指定
DEV_ID = 0

# パラメータ
WIDTH = 640
HEIGHT = 480

def main():
    # /dev/video0を指定
    cap = cv2.VideoCapture(DEV_ID)

    # 解像度の指定
    cap.set(cv2.CAP_PROP_FRAME_WIDTH, WIDTH)
    cap.set(cv2.CAP_PROP_FRAME_HEIGHT, HEIGHT)

    # キャプチャの実施
    ret, frame = cap.read()
    if ret:
        # ファイル名に日付を指定
        date = datetime.now().strftime("%Y%m%d_%H%M%S")
        path = "./" + date + ".jpg"
        cv2.imwrite(path, frame)

    # 後片付け
    cap.release()
    cv2.destroyAllWindows()
    return

if __name__ == "__main__":
    main()
masato1004 commented 1 year ago

旧OSでAFカメラを使用できる? Arducamの高解像度カメラを使う

19238901 commented 1 year ago

1.BullseyeでAP化1 ※これだけじゃできなかった. 2.BullseyeでAP化2 2に従いwifiの設定を削除後,rebootでできた?

hostapd.confの比較

スクリーンショット 2023-04-13 15 22 43

※左が1,右が2

masato1004 commented 1 year ago

Capture with IMX519

test

masato1004 commented 1 year ago

オートフォーカスカメラの使用感

ひとまずターミナルでもPythonコードでも使用できることは確認できていて,cv2の行列の形と一致させられる.(cv2でimshowのコードが動いている)

画質

現状問題点