zoukankan      html  css  js  c++  java
  • Python人工智能第二篇:人脸检测和图像识别

    Python人工智能第二篇:人脸检测和图像识别

    人脸检测

    详细内容请看技术文档:https://ai.baidu.com/docs#/Face-Python-SDK/top

    from aip import AipFace
    import base64
    
    """ 你的 APPID AK SK """
    APP_ID = '你的 App ID'
    API_KEY = '你的 Api Key'
    SECRET_KEY = '你的 Secret Key'
    
    face_client = AipFace(APP_ID, API_KEY, SECRET_KEY)
    
    """ 读取图片 """
    def get_file_content(filePath):
    	with open(filePath, 'rb') as fp:
    		return fp.read()
    
    
    bytes_str = base64.b64encode(get_file_content('people/1.jpg'))
    image = str(bytes_str, "utf8")
    
    imageType = "BASE64"
    
    options = {}
    options["face_field"] = "age,beauty"
    """ 调用人脸检测 """
    res = face_client.detect(image, imageType, options)
    
    age = res.get("result").get("face_list")[0].get("age")
    beauty = res.get("result").get("face_list")[0].get("beauty")
    print(f"年龄:{age}岁", f"颜值:{beauty}分")
    

    图像识别

    详细内容请看技术文档:https://ai.baidu.com/docs#/ImageClassify-Python-SDK/top

    from aip import AipImageClassify
    
    """ 你的 APPID AK SK """
    APP_ID = '你的 App ID'
    API_KEY = '你的 Api Key'
    SECRET_KEY = '你的 Secret Key'
    
    client = AipImageClassify(APP_ID, API_KEY, SECRET_KEY)
    
    """ 读取图片 """
    def get_file_content(filePath):
    	with open(filePath, 'rb') as fp:
    		return fp.read()
    
    image = get_file_content('erha.jpg')
    """ 如果有可选参数 """
    options = {}
    options["top_num"] = 1  #返回预测得分top结果数,默认为6
    options["baike_num"] = 5    #返回百科信息的结果数,默认不返回
    
    """ 带参数调用动物识别 """
    res = client.animalDetect(image, options)
    
    print(res)
    
    
  • 相关阅读:
    MySQL主从复制
    Mysql解压版安装配置
    MySQL 多行数据合并 GROUP_CONCAT
    Java集合框架
    Redis 入门知识点
    事务
    Spring AOP 知识点入门
    Tomcat热部署和热加载
    Java的Socket通信简单实例
    nginx和tomcat配置负载均衡和session同步
  • 原文地址:https://www.cnblogs.com/an-wen/p/11604106.html
Copyright © 2011-2022 走看看