forked from vanditiit/Code42Day-Event
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_api.py
36 lines (29 loc) · 1.31 KB
/
test_api.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
# -*- coding: cp1252 -*-
# import the necessary packages
import requests
import cv2
# define the URL to our face detection API
url = "http://localhost:8000/face_detection/detect/"
# use our face detection API to find faces in images via image URL
image = cv2.imread("H:\ \Code42Day-Event-master\Code42Day-Event-master\Test Images\3.jpg")
payload = {"url": "https://i.ytimg.com/vi/a01QQZyl-_I/hqdefault.jpg"}
r = requests.post(url, data=payload).json()
print "3.jpg: {}".format(r)
#loop over the faces and draw them on the image
for (startX, startY, endX, endY) in r["faces"]:
cv2.rectangle(image, (startX, startY), (endX, endY), (0, 255, 0), 2)
# show the output image
cv2.imshow("3.jpg", image)
cv2.waitKey(0)
# load our image and now use the face detection API to find faces in
# images by uploading an image directly
image = cv2.imread("H:\ \Code42Day-Event-master\Code42Day-Event-master\Test Images\3.jpg")
payload = {"image": open("H:\ \Code42Day-Event-master\Code42Day-Event-master\Test Images\3.jpg", "rb")}
r = requests.post(url, files=payload).json()
print "adrian.jpg: {}".format(r)
# loop over the faces and draw them on the image
for (startX, startY, endX, endY) in r["faces"]:
cv2.rectangle(image, (startX, startY), (endX, endY), (0, 255, 0), 2)
# show the output image
cv2.imshow("3.jpg", image)
cv2.waitKey(0)