This repository was archived by the owner on Feb 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathface_rec_server.py
More file actions
53 lines (30 loc) · 1.61 KB
/
face_rec_server.py
File metadata and controls
53 lines (30 loc) · 1.61 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/home/server/miniconda2/bin/python
import cv2
import numpy as np
import json
import timeit
import sys
import os
import cgitb
cgitb.enable()
print("Content-type: text/html; charset=utf-8")
print("\n")
if os.environ.get("REQUEST_METHOD") == "POST":
# load OpenCV cascade classifier file for detecting faces
faceCascade = cv2.CascadeClassifier('../../../home/server/Downloads/opencv/data/haarcascades/haarcascade_frontalface_default.xml')
posted_content = sys.stdin.read().decode() # receive frame from PandaBoard as string
img = json.loads(posted_content) # load frame as JSON string
img = json.loads(img[0]) # load frame as JSON string again
img = np.array(img, dtype=np.uint8) # convert frame into numpy array with data type set to
# unsigned 8 bit integer (i.e. values from 0-255)
#
# Function: detectMultiScale
# Description: Perform face detection and returns the position of the rectangle
# where the face is detected
# Input: frame in color scale, scaleFactor is used to compensate for faces appearing bigger
# because they are closer to the camera, minNeighbors defines how many objects
# are detected near the current one before it declares that a face is found
# Output: Returns the position of the rectangle where the face is detected
#
faces = faceCascade.detectMultiScale(img, 1.3, 5)
print(faces) # print the position of the rectangle so that it can returned to the PandaBoard