-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathproject1.py
36 lines (33 loc) · 1.02 KB
/
project1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#comments
import cv2
import numpy as np
import urllib
a=12
face_data="haarcascade_frontalface_default.xml"
classifier=cv2.CascadeClassifier(face_data)
URL='http://10.20.246.217:8080/shot.jpg'
data=[] //changes
ret=True
while ret:
image_url=urllib.request.urlopen(URL)
image=np.array(bytearray(image_url.read()),np.uint8)
frame=cv2.imdecode(image,-1)
faces=classifier.detectMultiScale(frame)
if faces is not None:
for x,y,w,h in faces:
face_image=frame[y:y+h,x:x+w].copy()
if len(data)<=150:
data.append(face_image)
else:
cv2.putText(frame,'complete',(250,250),
cv2.FONT_HERSHEY_PLAIN,1,(255,0,0),2)
cv2.rectangle(frame,(x,y),(x+w,y+h),(0,255,255),2)
cv2.imshow('capturing',frame)
if cv2.waitKey(1)==27:
break;
cv2.destroyAllWindows()
name = input('Enter the name')
c=0
for i in data:
cv2.imwrite('images/'+name+'_'+str(c)+'.jpg',i)
c+=1