会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132382个问题
Python 全系列/第三阶段:Python 网络与并发编程/网络通信 36961楼
JAVA 全系列/第十四阶段:全文检索服务/Spring Data For ElasticSearch 36962楼
JAVA 全系列/第一阶段:JAVA 快速入门/面向对象详解和JVM底层内存分析 36963楼
WEB前端全系列/第五阶段:前后端交互/PHP、数据库编程与设计 36964楼
Python 全系列/第一阶段:Python入门/序列 36965楼

1658051952399.png

mybatisDemo2.rar

老师给我看下是哪里出错了


JAVA 全系列/第六阶段:项目管理与SSM框架/Mybatis 36966楼

# 图片识别
import base64
from PIL import Image
from aip import AipFace
from PIL import Image, ImageDraw, ImageFont
APP_ID = '23157414'
API_KEY = 'WhceDbN1GR7OpsYGguhvpgiu'
SECRET_KEY = 'NA6N6UxpsfSlQ6GgnAMuf9jvZ1UtTZHX'
client = AipFace(APP_ID, API_KEY, SECRET_KEY)

filename = './图片/1.jpg'
fo = open(filename, 'rb')
image = fo.read()
fo.close()
image = str(base64.b64encode(image), 'utf-8')
image_type = 'BASE64'

options = {}
options['face_field'] = 'age,gender,beauty,glasses'
options['max_face_num'] = 10
options['face_type'] = 'LIVE'
result = client.detect(image, image_type, options)
print(result)
img = Image.open(filename)
img.show()

for face in result['result']['face_list']:
    if face['gender']['type'] == 'male':
        gender = '男'
    else:
        gender = '女'
    age = face['age']
    beauty = face['beauty']
    if face['glasses']['type'] == 'none':
        glasses = '没戴眼镜'
    else:
        glasses = '戴眼镜'
    print('性别:' + gender)
    print('年龄:' + str(age))
    print('颜值:' + str(beauty))
    print(glasses + '\n')

img =Image.open(filename)
draw = ImageDraw.Draw(img)
ttfont = ImageFont.truetype('C:\Windows\Fonts\Deng.ttf', 12)

for face in result['result']['face_list']:
    if face['gender']['type'] == 'male':
        gender = '男'
    else:
        gender = '女'
    age = face['age']
    beauty = face['beauty']
    if face['glasses']['type'] == 'none':
        glasses = '没戴眼镜'
    else:
        glasses = '戴眼镜'

    x1 = face['location']['left']
    y1 = face['location']['top']
    x2 = x1+face['location']['width']
    y2 = y1+face['location']['height']
    draw.rectangle((x1, y1, x2, y2), outline='blue')

    x = x2+5
    draw.text([x, y1], '性别:'+gender, 'white', font=ttfont)
    draw.text([x, y1+15], '年龄'+str(age), 'white', font=ttfont)
    draw.text([x, y1+30], '颜值'+str(beauty), 'white', font=ttfont)
    draw.text([x, y1+45], glasses, 'white', font=ttfont)
img.show()

老师,我想在这个代码里加一个就是当识别的图片中没有人物是在图片中显示‘’此图片中没有人物‘’这样的代码,老师你帮我看看怎么加




Python 全系列/第一阶段:Python入门/面向对象 36968楼
JAVA 全系列/第五阶段:JavaWeb开发/Servlet技术详解 36969楼
JAVA 全系列/第五阶段:JavaWeb开发/Servlet技术详解(旧) 36970楼
Python 全系列/第二阶段:Python 深入与提高/文件处理 36971楼
Python 全系列/第一阶段:Python入门/面向对象 36973楼

111111111.PNG

222222222.PNG

老师我这结果和您视频里的有点出入,想问一下为什么

Python 全系列/第一阶段:Python入门/面向对象 36974楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637