I have a face recognition with webcam code using tensorflow and deepface. It is written in Intelij IDEA, and there it works fine. When i try to pack it into the .exe file and launch it, it gives me that error. After that code seems to start to work, but only partionally. Part of code where it recognizes my face from webcam doesn't work(says 'no faces found' and etc.). And again, in intelij it works

import tensorflow as tf
import os
import threading
from datetime import datetime
import cv2
import openpyxl
from deepface import DeepFace

debug_txt = open("C:\\Users\\alexp\\IdeaProjects\\скрипты и прочее\\debug_face_recognition.txt", "a")
debug_txt.write("\n")
debug_txt.write("--Новый процесс--")
debug_txt.write("\n")

mnist = tf.keras.datasets.mnist
__all__ = [os, threading, cv2, openpyxl, datetime, DeepFace, tf]

cap = cv2.VideoCapture(2, cv2.CAP_DSHOW)

cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)

counter = 0
count2 = 0
face_match = ""

AE_img = cv2.imread("C:\\Users\\alexp\\IdeaProjects\\faceR\\A.E..jpg")
EA_img = cv2.imread("C:\\Users\\alexp\\IdeaProjects\\faceR\\E.A..jpg")
IA_img = cv2.imread("C:\\Users\\alexp\\IdeaProjects\\faceR\\I.A..jpg")
AN_img = cv2.imread("C:\\Users\\alexp\\IdeaProjects\\faceR\\A.N..jpg")

# dir = os.path.dirname(__file__)
# dir2 = os.path.split(dir)
dir3 = "C:\\Users\\alexp\\IdeaProjects\\скрипты и прочее\\saved.xlsx"
debug_txt.write("Расположение saved.xlsx - " + dir3)
debug_txt.write("\n")
# print(os.path.abspath(__file__))
print("saved.xlsx directory: " + dir3)

wb_obj = openpyxl.load_workbook(dir3)
sheet_obj = wb_obj.active
cell_obj = sheet_obj.cell(row=5, column=1)
cell_date = sheet_obj.cell(row=5, column=2)
t = cell_date.value.strftime('%d/%m/%y %H:%M:%S')


def check_face(frame):
    global face_match
    try:
        if DeepFace.verify(frame, AE_img.copy())['verified']:
            face_match = "Antipov A.E."
            pass
        elif DeepFace.verify(frame, EA_img.copy())['verified']:
            face_match = "Antipov E.A."
            pass
        elif DeepFace.verify(frame, IA_img.copy())['verified']:
            face_match = "Antipova I.A."
            pass
        elif DeepFace.verify(frame, AN_img.copy())['verified']:
            face_match = "Kruzhilin A.N."
            pass
        else:
            face_match = "Unidentified"

        debug_txt.write("Распознан - " + face_match)
        debug_txt.write("\n")

    except ValueError:
        face_match = "Unidentified"
        print("ValueError")


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

    if ret:
        if counter % 30 == 0:
            try:
                threading.Thread(target=check_face, args=(frame.copy(),)).start()
            except ValueError:
                debug_txt.write("ValueError1")
                debug_txt.write("\n")
                print("ValueError1")
                pass
        counter += 1
        if face_match != "Unidentified":
            count2 += 1
            cv2.putText(frame, face_match, (60, 450), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 3)
            if count2 < 90:
                print(count2)
            if 30 < count2 < 60:
                cv2.putText(frame, "1", (20, 450), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 3)
            elif 60 < count2 < 90:
                cv2.putText(frame, "2", (20, 450), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 0), 3)
            elif count2 >= 90:
                cv2.putText(frame, "3", (20, 450), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 3)
                pass
        else:
            cv2.putText(frame, face_match, (20, 450), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 3)

        cv2.imshow("video", frame)

    key = cv2.waitKey(1)
    if face_match != "Unidentified" and count2 >= 95:
        debug_txt.write("Лицо распознано 90 раз, ПРИНЯТО")
        debug_txt.write("\n")
        cell_obj.value = face_match
        cell_date.value = datetime.now()
        t1 = cell_date.value.strftime('%d/%m/%y %H:%M:%S')
        print("out name: " + cell_obj.value + " out date: " + t1)
        wb_obj.save(dir3)
        recognised_faces = open("C:\\Users\\alexp\\IdeaProjects\\скрипты и прочее\\Распознанные лица.txt", "a")
        recognised_faces.write("\n")
        recognised_faces.write("name: " + cell_obj.value + " date: " + t1)
        recognised_faces.close()
        debug_txt.write("Имя: " + cell_obj.value + " Время: " + t1)
        debug_txt.write("\n")
        break
    elif key == ord(" "):
        break

    cv2.destroyAllWindows

dont want to change method of recognising

0

There are 0 best solutions below