Advertisement
matedon

pymagepeople

Feb 21st, 2024
1,082
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.03 KB | None | 0 0
  1. #!/usr/bin/env python
  2. '''
  3. python 3.10
  4. To install all required modules:
  5. pip install -r requirements.txt
  6. To update required modules:
  7. pip install pipreqs
  8. pipreqs . --force
  9. '''
  10.  
  11. import os
  12. import cv2
  13. from datetime import datetime
  14.  
  15. # Képernyő felbontásának lekérdezése
  16. screen_width, screen_height = 1920, 1080  # Példa érték
  17.  
  18. # Mappa elérési útvonala, ahol a képek találhatók
  19. folder_path = os.path.join(os.getcwd(), 'work_images')
  20.  
  21. # Mappa elérési útvonala, ahol a számított képek lesznek
  22. output_folder = os.path.join(os.getcwd(), 'computed_images')
  23. # Mappa létrehozása az eredményeknek
  24. current_date_time = datetime.now().strftime('%Y%m%d_%H%M%S')
  25. output_folder_path = os.path.join(output_folder, current_date_time)
  26. os.makedirs(output_folder_path)
  27.  
  28. # Arckereső szűrők
  29. cascades_paths = [
  30.     'haarcascade_frontalface_alt.xml',
  31.     'haarcascade_frontalface_alt2.xml',
  32.     'haarcascade_frontalface_alt_tree.xml',
  33.     'haarcascade_frontalface_default.xml',
  34.     'haarcascade_eye_tree_eyeglasses.xml',
  35.     'haarcascade_profileface.xml',
  36.     'haarcascade_fullbody.xml',
  37.     'haarcascade_upperbody.xml',
  38. ]
  39.  
  40. # Színek definiálása
  41. colors = [
  42.     (255, 0, 0),    # Piros
  43.     (0, 255, 0),    # Zöld
  44.     (0, 0, 255),    # Kék
  45.     (255, 255, 0),  # Sárga
  46.     (255, 0, 255),  # Lila
  47.     (0, 255, 255),  # Cián
  48.     (128, 0, 0),    # Sötét piros
  49.     (0, 128, 0),    # Sötét zöld
  50.     (0, 0, 128),    # Sötét kék
  51.     (128, 128, 0)   # Sötét sárga
  52. ]
  53.  
  54. # Minden kép feldolgozása
  55. for filename in os.listdir(folder_path):
  56.     if filename.endswith(".jpg"):
  57.         # Kép betöltése
  58.         img_path = os.path.join(folder_path, filename)
  59.         print(img_path)
  60.         img = cv2.imread(img_path)
  61.  
  62.  
  63.         # Kép átalakítása szürkeárnyalatosra
  64.         gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  65.  
  66.         # Minden szűrő alkalmazása
  67.         for idx, cascade_path in enumerate(cascades_paths):
  68.             # CascadeClassifier létrehozása
  69.             face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + cascade_path)
  70.  
  71.  
  72.             # Arcok detektálása a képen
  73.             faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5)
  74.  
  75.             # Felismert arcok keretezése a képen
  76.             for (x, y, w, h) in faces:
  77.                 cv2.rectangle(img, (x, y), (x+w, y+h), colors[idx % len(colors)], 2)
  78.  
  79.         # Eredmény kép mentése
  80.         output_file_path = os.path.join(output_folder_path, filename)
  81.         cv2.imwrite(output_file_path, img)
  82.  
  83.  
  84.         # Kép méretarányának meghatározása
  85.         #ratio = min(screen_width / img.shape[1], screen_height / img.shape[0])
  86.         # Kép átméretezése
  87.         #resized_img = cv2.resize(img, (int(img.shape[1] * ratio), int(img.shape[0] * ratio)))
  88.  
  89.         # Eredmények megjelenítése
  90.         #cv2.imshow('Detected Faces', resized_img)
  91.         #cv2.imshow('Detected Faces', img)
  92.         #cv2.waitKey(1000)  # Várunk egy másodpercet az eredmény megjelenítésére
  93.  
  94. cv2.destroyAllWindows()
  95.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement