Dave from DesignSpark
How do you feel about this article? Help us to provide better content for you.
Dave from DesignSpark
Thank you! Your feedback has been received.
Dave from DesignSpark
There was a problem submitting your feedback, please try again later.
Dave from DesignSpark
What do you think of this article?
由于军旗采用暗棋的形式对战,一场军棋对局需要3个人,在缺少军师的情况下2人无法下棋。针对上述痛点开发出了智能军师。在吃子时自行判断双方大小,省去了一个人工军师
文字识别
调用百度api接口
根据棋子位置判断红方黑方
识别到双方棋子后自动关闭摄像头
自动过滤无效信息,提高识别精度,适应各种款式军旗
ii=0
key=['','']
cap=cv2.VideoCapture(0)
while True:
ret,frame=cap.read()
cv2.imshow('Video',frame)
cv2.imwrite('q.jpg',frame)
with open('q.jpg','rb') as f:
image=f.read()
text=client.basicGeneral(image)
for i in text.get('words_result'):
key[ii]=i.get('words')
ii+=1
if ii==2:
ii=0
red=key[0]
black=key[1]
if cv2.waitKey(1)&0xFF==ord('q')or len(black)>1:
break
cap.release()
cv2.destroyAllWindows()
使用字典存储各个棋子大小,比较时直接取对应键值,提高代码效率
dic=dict(地雷=12,司令=11, 军长=10, 师长=9,旅长=8,团长=7,营长=6,连长=5,排长=4,工兵=3,爆破=2)
进入正式逻辑判断前先进行预判,对炸弹及地雷/工兵多属性情况执行预处理。
if red=='炸弹'or black=='炸弹':
black='爆破'
red=black
elif red=='地雷'and black=='工兵':
red='爆破'
elif black=='地雷'and red=='工兵':
black='爆破'
对吃子胜负进行正式判断,并更新界面及语音提示
if red=='军旗 ':
play()
tkinter.Label(sign_up, text='黑方胜', font=('Times', 28,'bold'),bg='yellow',wraplength = 1,anchor = 'w').place(x=220, y=140)
elif black=='军旗':
tkinter.Label(sign_up, text='红方胜', font=('Times', 28,'bold'),bg='yellow',wraplength = 1,anchor = 'w').place(x=220, y=140)
play()
elif len(black)>1 and dic.get(red)>dic.get(black):
print(red,'赢')
tkinter.Label(sign_up, text='红方留子', font=('Times', 20,'bold'),bg='white',wraplength = 1,anchor = 'w').place(x=220, y=140)
x+=1
tkinter.Label(sign_up, text='伤亡:%d'%x, font=('Times', 18,'bold')).place(x=335, y=200)
speaker.Speak('红方留子’)
elif len(black)>1 and dic.get(red)==dic.get(black):
print('平')
x+=1
y+=1
tkinter.Label(sign_up, text='同归于尽', font=('Times', 20,'bold'),bg='white',wraplength = 1,anchor = 'w').place(x=220, y=140)
tkinter.Label(sign_up, text='伤亡:%d'%y, font=('Times', 18,'bold')).place(x=55, y=200)
tkinter.Label(sign_up, text='伤亡:%d'%x, font=('Times', 18,'bold')).place(x=335, y=200)
speaker.Speak('同归于尽')
else:
print(black,'黑赢')
y+=1
tkinter.Label(sign_up, text='黑方留子', font=('Times', 20,'bold'),bg='white',wraplength = 1,anchor = 'w').place(x=220, y=140)
tkinter.Label(sign_up, text='伤亡:%d'%y, font=('Times', 18,'bold')).place(x=55, y=200)
speaker.Speak('黑方留子')
UI界面
工业设计
图像识别技术判断双方大小
高清触控屏简化人机交互
语音提示带来沉浸式体验
未来可通过OTA升级实现智能闹钟、智能音箱等功能
下载Github源代码,了解更多详情。
提示:
- 将8813.wav、logo.gif、智能军师.py文件放在同一路径下即可启动软件
- 使用win10自带软件print 3D打开"外形.3mf"后点击"启动3D Builder"可展现硬件
Comments