SHARE
TWEET

g贸wno

a guest Jun 18th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import numpy as np
  2. import cv2
  3. import os
  4. import sys
  5.  
  6. #validator parametru imienia
  7. your_name= sys.argv[1:]
  8. if len(your_name) == 0:
  9.     print("type your name-surname as a parameter")
  10.     exit()
  11.  
  12. os.makedirs('images/'+str(your_name))
  13.  
  14. face_cascade = cv2.CascadeClassifier('cascades/data/haarcascade_frontalface_alt2.xml')
  15. cap = cv2.VideoCapture(0)
  16. i = 0
  17. while(True):
  18.     #przechwytywanie obrazu
  19.     ret, frame = cap.read()
  20.  
  21.     # operacje na poszczeg贸lnych klatkach (zmiana koloru na czarno-bia艂y etc)
  22.     gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
  23.     faces = face_cascade.detectMultiScale(gray, scaleFactor=1.5, minNeighbors=5)
  24.     for (x, y, w, h) in faces:
  25.         #print(x,y,w,h)
  26.         roi_gray = gray[y:y+h, x:x+w]
  27.         roi_color = frame[y:y+h, x:x+w]
  28.         #zapisywanie klatek do folderu
  29.         i=i+1
  30.         print(i)
  31.         cv2.imwrite('images/'+str(your_name)+'/picture'+str(i)+'.png', frame)
  32.     #po 200 zdj臋ciach ko艅czy przechwytywanie obrazu
  33.     if i == 200: break
  34.  
  35.    #wy艣wietlenie obrazu oraz zamkni臋cie okna
  36.     cv2.imshow('frame',frame)
  37.     cv2.imshow('gray',gray)
  38.     if cv2.waitKey(20) & 0xFF == ord('q'):
  39.         break
  40.  
  41. cap.release()
  42. cv2.destroyAllWindows()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top