sairate c4d32e8092 feat(第7讲 字母卡牌): 实现记忆游戏并添加开始界面
- 新增 jiyi.py 文件,实现字母翻牌记忆游戏功能
- 添加 youxijiemian.py 文件,创建游戏开始界面
- 使用 turtle 和 tkinter 模块分别实现游戏和界面
- 支持选择不同难度的游戏模式
2025-06-28 14:27:31 +08:00

46 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
》》》运行前必做《《《
1. 运行【安装第三方库.py】文件
2. 注册百度云账号获取API配置后查看完整效果
账号注册指南:
https://huewq7h021.feishu.cn/wiki/Ry3UwaoceiMRXgklbWtc9mEUn9f?from=from_copylink
"""
from aip import AipImageClassify # 调用百度智能模块中图像识别类方法
# 填写个人的授权使用信息
APP_ID = '你的 AppID'
API_KEY = '你的 API Key'
SECRET_KEY = '你的 Secret Key'
# 准备【图像识别器】
client = AipImageClassify(APP_ID, API_KEY, SECRET_KEY)
# 读取图片文件并返回二进制数据
def read_img(file):
with open(file, "rb") as f:
return f.read()
# 调用【图像识别器】并返回结果
def find_img(img):
# 返回的信息是字典类型结果保存在键result的值中
return client.advancedGeneral(img)
# 打印识别结果
def print_result(res):
if 'result' in res:
for i in res['result']:
if i['score'] >= 0.6:
print(f"结果为 {i['keyword']} , 相似度为 {i['score']*100:.2f}% ")
else:
# 失败响应提示信息
print(f"识别失败, 错误码: {res.get('error_code')}, 错误信息: {res.get('error_msg')}")
# 主函数
data = read_img("花.png")
result = find_img(data)
print(f"API返回结果{result}\n")
print_result(result)
print('识别完毕')