Python Forum
How to unlock pc using opencv - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How to unlock pc using opencv (/thread-31974.html)



How to unlock pc using opencv - Tyrel - Jan-13-2021

Can someone please help me.
I'm trying to unlock my pc using opencv, here is my current code. It opens up a window with my laptop camera and detects my face but now how do I make it unlock pc when it detects my face and run it when on lock screen.

import numpy as np
import face_recognition as fr
import cv2

video_capture = cv2.VideoCapture(0)

Tyrel_image = fr.load_image_file("Tyrel.jpg")
Tyrel_face_encoding = fr.face_encodings(Tyrel_image)[0]

known_face_encondings = [Tyrel_face_encoding]
known_face_names = ["Tyrel"]

while True: 
    ret, frame = video_capture.read()

    rgb_frame = frame[:, :, ::-1]

    face_locations = fr.face_locations(rgb_frame)
    face_encodings = fr.face_encodings(rgb_frame, face_locations)

    for (top, right, bottom, left), face_encoding in zip(face_locations, face_encodings):

        matches = fr.compare_faces(known_face_encondings, face_encoding)

        name = "Unknown"

        face_distances = fr.face_distance(known_face_encondings, face_encoding)

        best_match_index = np.argmin(face_distances)
        if matches[best_match_index]:
            name = known_face_names[best_match_index]
        
        cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)

        cv2.rectangle(frame, (left, bottom -35), (right, bottom), (0, 0, 255), cv2.FILLED)
        font = cv2.FONT_HERSHEY_SIMPLEX
        cv2.putText(frame, name, (left + 6, bottom - 6), font, 1.0, (255, 255, 255), 1)

    cv2.imshow('Webcam_facerecognition', frame)



    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

video_capture.release()
cv2.destroyAllWindows()



RE: How to unlock pc using opencv - Marbelous - Jan-13-2021

You didn't specify so I'm assuming you're talking about Windows.

I don't think Python and OpenCV can't help you here. You will need to access the WinAPI LockScreen classes. I know they expose simple things like changing the background image and locking the PC but I doubt they will allow access to unlock the OS as that would be a pretty severe security breach. Try looking into Windows Hello and see if there's any new APIs for that. It already has the unlock by face recognition built in so maybe MS now lets you access those functions? Again though, allowing a third party tool access to OS security seems like a bad idea.

Of course you can always just use Windows Hello.


RE: How to unlock pc using opencv - Tyrel - Jan-13-2021

ok thanx anyway


RE: How to unlock pc using opencv - Tyrel - Jan-13-2021

(Jan-13-2021, 03:08 PM)Marbelous Wrote: You didn't specify so I'm assuming you're talking about Windows.

I don't think Python and OpenCV can't help you here. You will need to access the WinAPI LockScreen classes. I know they expose simple things like changing the background image and locking the PC but I doubt they will allow access to unlock the OS as that would be a pretty severe security breach. Try looking into Windows Hello and see if there's any new APIs for that. It already has the unlock by face recognition built in so maybe MS now lets you access those functions? Again though, allowing a third party tool access to OS security seems like a bad idea.

Of course you can always just use Windows Hello.

So how would I say for example print test if it detects my face