faces = self.face_cascade.detectMultiScale(gray,1.3,5)
if len(faces)>0 :
for (x,y,w,h) in faces:
self.face_x=float(x+w/2.0)
self.face_y=float(y+h/2.0)
img = cv2.circle(img, (x+w/2,y+h/2), (w+h)/4, (0, 255, 0), 2)
else:
self.face_x=0
self.face_y=0
cv2.imwrite('video.jpg', img)
def streaming(self,ip):
stream_bytes = b' '
try:
self.client_socket.connect((ip, 8000))
self.connection = self.client_socket.makefile('rb')
except:
#print "command port connect failed"
pass
while True:
try:
stream_bytes= self.connection.read(4)
leng=struct.unpack('L', stream_bytes[:4])
jpg=self.connection.read(leng[0])
if self.IsValidImage4Bytes(jpg):
image = cv2.imdecode(np.frombuffer(jpg, dtype=np.uint8),
cv2.IMREAD_COLOR)
if self.video_Flag:
self.face_detect(image)
self.video_Flag=False
except:
break