python version 3.12.6 in my yacto version is not support cv2

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

python version 3.12.6 in my yacto version is not support cv2

1,049 Views
Velan
Contributor I

Hi, I'm using the yacto 2.8.0 version which has python 3.12.6 version default. i have written code for the driver monitoring system. i'm trying to import below lib for my project. but it fails in py3.12.6 but in py 3.10. version works fine. how to fix this issue

import cv2

import dlib

import numpy as npimport pygame

import os

from deepface import DeepFace

from scipy.spatial import distance



0 Kudos
Reply
5 Replies

1,011 Views
Manuel_Salas
NXP TechSupport
NXP TechSupport

Hello @Velan 

I hope you are doing very well.

 

I’ve reviewed the issue you're facing with importing opencv-python, dlib, deepface, etc., under Python 3.12.6 on Yocto 2.8.0. This problem happens because many of these libraries haven’t fully added support for Python 3.12 yet, especially the ones with C++ bindings like dlib.

 

The easiest and most future-proof solution is to tell Yocto to use Python 3.10 instead of 3.12. This way, the libraries will work as they did in your previous environment.

You can do this by adding these lines to your local.conf or custom layer config:

PREFERRED_VERSION_python3 = "3.10.%"
PREFERRED_VERSION_python3-native = "3.10.%"

 

Best regards,

Salas.

 

0 Kudos
Reply

984 Views
Velan
Contributor I

AFTER adding i'm getting warnings

WARNING: preferred version 3.10.% of python3 not available (for item python3)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-dev)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-fcntl-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-mmap-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-core-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-compression-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-misc-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-datetime)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-json)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-core)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-pickle)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-mailbox)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-syslog)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-pydoc)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-multiprocessing)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-tests)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-resource)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-html)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-plistlib)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-doctest)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-netserver)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-2to3)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-zipapp)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-audio)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-venv)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-fcntl)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-crypt)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-profile)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-email)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-unittest)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-netclient)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-debugger)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-db)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-compression)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-image)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-sqlite3)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-ensurepip)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-logging)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-difflib)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-codecs)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-gdbm)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-curses)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-unixadmin)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-shell)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-tomllib)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-pkgutil)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-mime)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-math)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-numbers)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-compile)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-tkinter)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-stringold)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-mmap)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-zoneinfo)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-pprint)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-modules)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-xml)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-ctypes)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-misc)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-asyncio)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-terminal)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-threading)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-io)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-cgitb)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-statistics)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-xmlrpc)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3 not available (for item python3-idle)
WARNING: versions of python3 available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-venv)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-debugger)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-idle)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-email)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-xmlrpc)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-resource)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-curses)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-fcntl)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-compression)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-unixadmin)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-mmap)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-asyncio)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-math)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-multiprocessing)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-terminal)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-modules)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-pickle)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-syslog)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-core)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-codecs)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-sqlite3)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-zoneinfo)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-statistics)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-numbers)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-ctypes)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-json)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-crypt)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-html)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-unittest)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-io)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-difflib)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-compile)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-doctest)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-2to3)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-image)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-datetime)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-plistlib)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-netserver)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-shell)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-mime)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-xml)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-db)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-audio)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-stringold)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-netclient)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-tkinter)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-threading)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-pkgutil)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-tomllib)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-logging)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-pprint)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-mailbox)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-profile)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-pydoc)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-native-ensurepip)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-numbers-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-pkgutil-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-email-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-netserver-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-stringold-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-shell-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-json-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-ctypes-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-html-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-threading-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-unittest-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-compile-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-xml-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-pickle-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-plistlib-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-io-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-netclient-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-tomllib-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-venv-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-ensurepip-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-difflib-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-logging-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-debugger-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-pprint-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-modules-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-doctest-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-datetime-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-multiprocessing-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-pydoc-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-profile-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-asyncio-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-math-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-crypt-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-image-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-xmlrpc-native)
WARNING: versions of python3-native available: 3.12.6
WARNING: preferred version 3.10.% of python3-native not available (for item python3-unixadmin-native)
WARNING: versions of python3-native available: 3.12.6

 

0 Kudos
Reply

960 Views
Manuel_Salas
NXP TechSupport
NXP TechSupport

Hello @Velan 

 

The behavior is expected. As you said Yocto 2.8.0 uses python 3.12.6, but it should works any way.

 

Best regards,

Salas. 

0 Kudos
Reply

881 Views
Velan
Contributor I

i'm facing issue in python 3.12.6
import package error for the following lib


import cv2
import dlib
import numpy as np
import pygame
import os
from deepface import DeepFace
from scipy.spatial import distance

0 Kudos
Reply

940 Views
Velan
Contributor I
import cv2
import dlib
import numpy as np
import pygame
import os
from deepface import DeepFace
from scipy.spatial import distance

# Initialize alert sound
pygame.mixer.init()
alert_sound = pygame.mixer.Sound("alert.wav") # Ensure this file exists

# Load Dlib’s face detector & landmark predictor
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat") # Ensure this file exists

# Define eye landmarks
LEFT_EYE = [36, 37, 38, 39, 40, 41]
RIGHT_EYE = [42, 43, 44, 45, 46, 47]

# Load multiple authorized faces
authorized_faces_dir = "authorized_faces/"
authorized_faces = [os.path.join(authorized_faces_dir, img) for img in os.listdir(authorized_faces_dir) if img.endswith(('.jpg', '.png', '.jpeg'))]
if not authorized_faces:
print(" Error: No authorized face images found in 'authorized_faces/' directory!")
exit(1)

# Define camera matrix for head pose estimation
focal_length = 640
center = (320, 240)
camera_matrix = np.array([
[focal_length, 0, center[0]],
[0, focal_length, center[1]],
[0, 0, 1]
], dtype="double")

dist_coeffs = np.zeros((4,1)) # No lens distortion

# Thresholds
EAR_THRESHOLD = 0.25
DROWSY_FRAMES = 30

drowsy_counter = 0
verified = False

def calculate_EAR(eye):
A = distance.euclidean(eye[1], eye[5])
B = distance.euclidean(eye[2], eye[4])
C = distance.euclidean(eye[0], eye[3])
return (A + B) / (2.0 * C)

def verify_identity(temp_face_path):
for authorized_face in authorized_faces:
try:
result = DeepFace.verify(img1_path=temp_face_path, img2_path=authorized_face, model_name="VGG-Face", detector_backend="opencv", enforce_detection=False)
if result["verified"]:
print(f" Access Granted! Matched with: {os.path.basename(authorized_face)}")
return True
except Exception as e:
print(f" Error during verification: {str(e)}")
return False

cap = cv2.VideoCapture(0)

while True:
ret, frame = cap.read()
if not ret:
break

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = detector(gray)

for face in faces:
shape = predictor(gray, face)
landmarks = np.array([[p.x, p.y] for p in shape.parts()], dtype="double")

left_eye = landmarks[LEFT_EYE]
right_eye = landmarks[RIGHT_EYE]
avg_EAR = (calculate_EAR(left_eye) + calculate_EAR(right_eye)) / 2.0

if avg_EAR < EAR_THRESHOLD:
drowsy_counter += 1
if drowsy_counter >= DROWSY_FRAMES:
cv2.putText(frame, "DROWSY ALERT!", (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 3)
alert_sound.play()
else:
drowsy_counter = 0

if not verified:
temp_face_path = "temp_face.jpg"
cv2.imwrite(temp_face_path, frame)
if verify_identity(temp_face_path):
verified = True
else:
print(" Access Denied! Face did not match any authorized users.")
exit(1)
os.remove(temp_face_path)

x, y, w, h = (face.left(), face.top(), face.width(), face.height())
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)

cv2.imshow("Driver Monitoring System", frame)
if cv2.waitKey(1) & 0xFF == ord("q"):
break

cap.release()
cv2.destroyAllWindows()

in this code importing lib are not avilable in the python 3.12
0 Kudos
Reply