Reputation: 1
I have been facing an issue. I have a project, where I have to use facial recognition from insightface to detect know people. Hardware-wise, I have been given a Raspberry pi 5 and two picams (v1.3, v2.1). I found out that there is an issue with the picam 2 not being detected by the system on pi5, so I am using the version 1.3. However, the issue I have been facing is the constant error AttributeError: module 'kms' has no attribute 'PixelFormat'.
To troubleshoot it, I reinstalled the picam2 library, verified that I do not have clashing versions, tried using no preview. No matter what I try, the error occurs.
import cv2
from picamera2 import Picamera2
import numpy as np
import pickle
from insightface.app import *
import Custom_Buzzer
from gpiozero import Device
from gpiozero.pins.lgpio import LGPIOFactory
Device.pin_factory = LGPIOFactory()
picam2 = Picamera2(preview=None)
picam2.configure(picam2.create_still_configuration(main={"format": "RGB888", "size": (640, 480)}))
picam2.start()
# Load the known face embeddings
with open("known_faces.pkl", "rb") as f:
known_face_encodings, known_face_names = pickle.load(f)
# Initialize the FaceAnalysis app
app = FaceAnalysis()
app.prepare(ctx_id=-1, det_size=(640, 640))
buzzer = Custom_Buzzer.create_buzzer(16)
while True:
# Capture frame-by-frame
frame = picam2.capture_array()
rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# Perform face detection
faces = app.get(rgb_frame)
for face in faces:
# Compute the face embedding
face_embedding = face.normed_embedding
# Compare against known faces
distances = np.linalg.norm(np.array(known_face_encodings) - face_embedding, axis=1)
min_distance_index = np.argmin(distances)
min_distance = distances[min_distance_index]
# Set a threshold for the distance to consider it a match
threshold = 1.0
if min_distance < threshold:
name = known_face_names[min_distance_index]
Custom_Buzzer.initialize_buzzer(buzzer, 2)
else:
name = "Unknown"
Custom_Buzzer.initialize_buzzer(buzzer, 5)
Upvotes: 0
Views: 103
Reputation: 1
This is not really a solution, as I believe an issue exists with the libraries currently, but I found a workaround, by basically saving short videos with libcamera which turns out to be functional, and then parsing that as input for analysis for the opencv
Upvotes: 0