faceDetectDemo.py 592 B

1234567891011121314151617181920
  1. import cv2, requests
  2. url = "http://localhost:8000/serviceApp/facedetect/" # web地址(http://localhost:8000)+访问接口(facedetect)
  3. # 上传图像并检测
  4. tracker = None
  5. imgPath = "face.jpg" #图像路径
  6. files = {
  7. "image": ("filename2", open(imgPath, "rb"), "image/jpeg"),
  8. }
  9. req = requests.post(url, data=tracker, files=files).json()
  10. print("获取信息: {}".format(req))
  11. # 将检测结果框显示在图像上
  12. img = cv2.imread(imgPath)
  13. for (w, x, y, z) in req["faces"]:
  14. cv2.rectangle(img, (w, x), (y, z), (0, 255, 0), 2)
  15. cv2.imshow("face detection", img)
  16. cv2.waitKey(0)