测试compreface的人脸检测和识别接口, http请求比httpx快一倍
This commit is contained in:
parent
0cee737d4c
commit
4fafd39d27
@ -1,6 +1,12 @@
|
||||
import requests
|
||||
from compreface import CompreFace
|
||||
from compreface.service import RecognitionService, DetectionService
|
||||
from compreface.collections import FaceCollection
|
||||
from compreface.collections.face_collections import Subjects
|
||||
import time
|
||||
|
||||
|
||||
DOMAIN: str = 'http://localhost'
|
||||
PORT: str = '8000'
|
||||
|
||||
def face_recognition_stream(image_path, url):
|
||||
with open(image_path, 'rb') as f:
|
||||
@ -12,9 +18,39 @@ def face_recognition_file(image_path, url):
|
||||
files = {"file": ("test.jpg", open(image_path, "rb"), "image/jpeg")}
|
||||
response = requests.post(url, files=files)
|
||||
return response.json()
|
||||
def face_recognition_compreface(image_path):
|
||||
|
||||
|
||||
API_KEY: str = 'a5924457-62c9-47dc-a6e7-15462c502d2c'
|
||||
|
||||
compre_face: CompreFace = CompreFace(DOMAIN, PORT)
|
||||
|
||||
recognition: RecognitionService = compre_face.init_face_recognition(API_KEY)
|
||||
|
||||
start_time = time.time()
|
||||
result = recognition.recognize(image_path=image_path)
|
||||
print("--- %s seconds ---" % (time.time() - start_time))
|
||||
print(result)
|
||||
|
||||
def face_detection_compreface(image_path):
|
||||
|
||||
|
||||
API_KEY: str = '070283a2-faa3-423b-9772-2cd48ecc5362'
|
||||
|
||||
compre_face: CompreFace = CompreFace(DOMAIN, PORT)
|
||||
|
||||
detection: DetectionService = compre_face.init_face_detection(API_KEY)
|
||||
|
||||
start_time = time.time()
|
||||
result = detection.detect(image_path=image_path)
|
||||
print("--- %s seconds ---" % (time.time() - start_time))
|
||||
print(result)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
image_path = './moshengren.jpg'
|
||||
url = 'http://10.0.0.202:9099/system/compreface/face_recognition'
|
||||
# print(face_recognition_stream(image_path, url))
|
||||
print(face_recognition_file(image_path, url))
|
||||
# print(face_recognition_file(image_path, url))
|
||||
# face_recognition_compreface(image_path)
|
||||
face_detection_compreface(image_path)
|
||||
Loading…
Reference in New Issue
Block a user