文档首页 > > 开发指南> EIServices模块> 示例-EIServices模块

示例-EIServices模块

分享
更新时间:2020/03/12 GMT+08:00

EIServices模块输出示例代码如下:

import hilens
import cv2
import numpy as np
import base64
import json

def run():
    # 使用图片作为输入
    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)

    # 使用Mat格式或者直接从摄像头输入
    #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()  # 将图片编码成流数据,放到内存缓存中,然后转化成string格式
    b64_code = base64.b64encode(img_str) # 编码成base64
    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()
分享:

    相关文档

    相关产品

文档是否有解决您的问题?

提交成功!非常感谢您的反馈,我们会继续努力做到更好!
反馈提交失败,请稍后再试!

*必选

请至少选择或填写一项反馈信息

字符长度不能超过200

提交反馈 取消

如您有其它疑问,您也可以通过华为云社区问答频道来与我们联系探讨

智能客服提问云社区提问