Updated on 2022-02-22 GMT+08:00
Example - EIServices Module
The following is an example of the output code of the EIServices module:
import hilens import cv2 import numpy as np import base64 import json def run(): # Use an image as the input. f=open('/tmp/dengchao.jpg','rb') base_f=base64.b64encode(f.read()) f_string=base_f.decode('utf-8') response0 = hilens.EIServices.HumanDetect(f_string) print(response0.requestState) print(response0.responseBody) # Use the Mat format or directly input the image from the camera. #img = cv2.imread("/tmp/dengchao.jpg") cap = hilens.VideoCapture() frame = cap.read() img = cv2.cvtColor(frame, cv2.COLOR_YUV2BGR_NV21) img_str = cv2.imencode('.jpg', img) [1].tostring() # Encode the image into stream data, store the stream data in the memory buffer, and convert the stream data into the string format. b64_code = base64.b64encode(img_str) # Encode the image into the Base64 format. f_string1=b64_code.decode('utf-8') response1 = hilens.EIServices.HumanDetect(f_string1) print(response1.requestState) print(response1.responseBody) headers = hilens.EIHeaders() body = {"image_base64": f_string} json_str = json.dumps(body) response5 = hilens.EIServices.Request(hilens.POST, "hilens-api.cn-north-4.myhuaweicloud.com", "/v1/human-detect", "", json_str, headers) print(response5.requestState) print(response5.responseBody) body1 = {"face_set_name": "ei_test"} json_str1 = json.dumps(body1) response6 = hilens.EIServices.Request(hilens.POST, "face.cn-north-4.myhuaweicloud.com", "/v1/fc3bc995e9c441369d71159c67404e88/face-sets", "", json_str1, headers) print(response6.requestState) print(response6.responseBody) response7 = hilens.EIServices.AddFace("ei_test", f_string, "") print(response7.requestState) print(response7.responseBody) response8 = hilens.EIServices.SearchFace("ei_test", f_string, 1, 0.93, "") print(response8.requestState) print(response8.responseBody) response9 = hilens.EIServices.Request(hilens.POST, "face.cn-north-4.myhuaweicloud.com","/v1/fc3bc995e9c441369d71159c67404e88/face-sets/ei_test/search", "", json_str, headers) print(response9.requestState) print(response9.responseBody) response10 = hilens.EIServices.Request(hilens.DELETE, "face.cn-north-4.myhuaweicloud.com", "/v1/fc3bc995e9c441369d71159c67404e88/face-sets/ei_test", "", "", headers) print(response10.requestState) print(response10.responseBody) response11 = hilens.EIServices.Request(hilens.GET, "face.cn-north-4.myhuaweicloud.com", "/v1/fc3bc995e9c441369d71159c67404e88/face-sets/ei_test", "", "", headers) print(response11.requestState) print(response11.responseBody) if __name__ == '__main__': hilens.init("hello") run() hilens.terminate()
Parent topic: EIServices Module
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot