Selaa lähdekoodia

Каждый раз вырезаем лицо

Alex Sidorov 1 vuosi sitten
vanhempi
commit
6257985ee3
4 muutettua tiedostoa jossa 17 lisäystä ja 4 poistoa
  1. 2 2
      module/ImageTool.py
  2. 9 0
      module/WorkWithDB.py
  3. 3 1
      module/cam/IPCam.py
  4. 3 1
      module/cam/USBCam.py

+ 2 - 2
module/ImageTool.py

@@ -27,7 +27,7 @@ def rotate_image(path_file: str, gradus: int = -90) -> str:
 
 
 
-def cupture_face(path_photo) -> None:
+def cupture_face(path_photo: str, new_path: str) -> None:
     img = cv2.imread(path_photo)
     face_recog = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
     face_result = face_recog.detectMultiScale(img, scaleFactor=2, minNeighbors=3)
@@ -37,7 +37,7 @@ def cupture_face(path_photo) -> None:
         x,y,w,h = face_result[-1]
         
         img = img[y-50:y+h+80,x-50:x+50+w]
-        cv2.imwrite(F"propusk_{datetime.now().timestamp()}.jpg", img)
+        cv2.imwrite(new_path, img)
             
         # cv2.imshow("Result", img)
         #Этот метод выводит результат на экран. Первый аргумент - что то по типу комментария к картинке, второй - сама картинка

+ 9 - 0
module/WorkWithDB.py

@@ -9,7 +9,10 @@ from logger import logger
 
 meta = MetaData()
 
+# /home/asidorov/Документы/propusk_db
+
 FILE_NAME = None
+
 if os.environ.get("DB_DIR"):
     FILE_NAME = os.path.join(os.environ.get("DB_DIR"), "propusk.db")
 else:
@@ -65,6 +68,12 @@ list_propusk = Table("list_propusk", meta,
                      Column("update", DateTime, default=func.now(),
                             onupdate=func.current_timestamp()))
 
+list_ussued_passes = Table("list_ussued_passes", meta,
+                           Column("id", Integer, primary_key=True),
+                           Column("used_pass", Integer, nullable=False),
+                           Column("id_propusk", Integer, ForeignKey("list_propusk.id_propusk"), nullable=False),
+                           Column("created", DateTime, default=func.now()),
+                           Column("update", DateTime, default=func.now(), onupdate=func.current_timestamp()))
 
 engine = create_engine(F"sqlite:///{FILE_NAME}", echo=False)
 engine.logging_name = 'PropuskLogger'

+ 3 - 1
module/cam/IPCam.py

@@ -3,7 +3,8 @@ from PySide6.QtCore import Qt
 from threading import Thread
 from PySide6.QtGui import QImage, QPixmap
 import cv2
-from module.ImageTool import create_filename
+from module import create_filename
+from module.ImageTool import cupture_face
 from logger import logger
 
 
@@ -75,4 +76,5 @@ class IPCam(Thread):
         qLabel.setPixmap(self.__scaled_img)
         self.__scaled_img.save(name_file, 'jpg')
         self.stop_cam()
+        cupture_face(name_file, F"face_{create_filename()}")
         return name_file

+ 3 - 1
module/cam/USBCam.py

@@ -8,7 +8,8 @@ from PySide6.QtMultimedia import (
     QMediaDevices, QCamera, QImageCapture, QMediaCaptureSession)
 from itertools import groupby
 from logger import logger
-from module.ImageTool import create_filename
+from module import create_filename
+from module.ImageTool import cupture_face
 
 if not os.environ.get("PHOTO_DIR"):
     logger.error("Не задана локальная переменная PHOTO_DIR")
@@ -93,6 +94,7 @@ class USBCam:
     def image_saved(self, id, fileName):
         load_image(self._label, fileName)
         self.stop_cam()
+        cupture_face(fileName, F"face_{create_filename()}")
 
 
 def load_image(qlabel: QLabel, path_file: str) -> None: