参赛作品名
【AI创造营】决战二仙桥(DodgeFace-EXQver)
作品简介
和前作DodgeFace操作方式一样,内部使用的技术换了:之前是ace2p,如果电脑配置不好的话,可能跑起来非常的卡。现在换成人脸检测的方式了,模型也用的比较小的模型,现在应该一般配置的就能丝滑享受吧(话是这么说,但是我也没多余的电脑来测。。。
使用方式
保证你的脸在摄像头可以拍摄的范围内,运行程序
python erxianqiao_map_skill.py
移动你的身体、转动你的头颅躲避那些…谭警官
如果没检测到你的脸会直接Game Over哦
如果不小心死掉了,按r重新开始,按其他的则退出游戏
如果你觉得游戏太过简单
python erxianqiao_map_skill.py --level X
X是一个正整数,X的默认值是5,如果你想加大难度,试试比5大的数吧
一些提示
增加了一些细节,更有主题了,这次是谭谈交通宇宙
既然是谭谈交通宇宙,除了二仙桥大爷和我们的谭sir,还有另外两个npc可能会出现
一个是灵魂歌手-气球哥
技能是让我们控制的二仙桥大爷多一条命
另一个是“从我身上下来”的强人锁男哥
技能是让全场的角色停止,不能运动n秒(替身攻击The World???)
希望大家玩得开心~
github
【AI创造营】决战二仙桥
#封装了一下检测模块,让视频流的检测更稳定一点
class detUtils():
def __init__(self):
super(detUtils, self).__init__()
self.lastres = None
self.module = hub.Module(name="ultra_light_fast_generic_face_detector_1mb_320")
def distance(self, a, b):
return math.sqrt(math.pow(a[0]-b[0], 2) + math.pow(a[1]-b[1], 2))
def iou(self, bbox1, bbox2):
b1left = bbox1['left']
b1right = bbox1['right']
b1top = bbox1['top']
b1bottom = bbox1['bottom']
b2left = bbox2['left']
b2right = bbox2['right']
b2top = bbox2['top']
b2bottom = bbox2['bottom']
area1 = (b1bottom - b1top) * (b1right - b1left)
area2 = (b2bottom - b2top) * (b2right - b2left)
w = min(b1right, b2right) - max(b1left, b2left)
h = min(b1bottom, b2bottom) - max(b1top, b2top)
dis = self.distance([(b1left+b1right)/2, (b1bottom+b1top)/2],[(b2left+b2right)/2, (b2bottom+b2top)/2])
if w <= 0 or h <= 0:
return 0, dis
iou = w * h / (area1 + area2 - w * h)
return iou, dis
def dodet(self, frame):
result = self.module.face_detection(images=[frame], use_gpu=True)
result = result[0]['data']
if isinstance(result, list):
if len(result) == 0:
return None, None
if len(result) > 1:
if self.lastres is not None:
maxiou = -float('inf')
maxi = 0
mind = float('inf')
mini = 0
for index in range(len(result)):
tiou, td = self.iou(self.lastres, result[index])
if tiou > maxiou:
maxi = index
maxiou = tiou
if td < mind:
mind = td
mini = index
if tiou == 0:
return result[mini], result
else:
return result[maxi], result
else:
self.lastres = result[0]
return result[0], result
else:
self.lastres = result[0]
return result[0], result
else:
return None, None
#基础技能类
class Skill():
def __init__(self, interval, gm):
self.stime = 0
self.interval = interval
self.gm = gm
self.finish = False
def trigger(self):
self.stime = time.time()
self.play()
def play(self):
pass
#气球哥的技能,加一条生命
class Balloon(Skill):
def __init__(self, interval, gm):
super(Balloon, self).__init__(interval, gm)
def play(self):
# print("Balloon Play")
if self.finish is False:
self.gm.glive()
if np.floor(time.time() - self.stime) >= self.interval:
self.finish = True
#强人锁男的技能,停止所有角色
class Lock(Skill):
def __init__(self, interval, gm):
super(Lock, self).__init__(interval, gm)
def play(self):
global llock
#print("Lock Play")
if self.finish is False:
llock = True
if np.floor(time.time() - self.stime) >= self.interval:
self.finish = True
llock = False
#print("Lock Play end:", llock)
#谭sir的技能,减一条命
class Tansir(Skill):
def __init__(self,interval, gm):
super(Tansir, self).__init__(interval, gm)
def play(self):
# print("Tansir Play")
if self.finish is False:
self.gm.nlive()
if np.floor(time.time() - self.stime) >= self.interval:
self.finish = True
#npc类,NPC都有一张贴图和一个技能
class Ball():
x = None
y = None
speed_x = None
speed_y = None
def __init__(self, x, y, speed_x, speed_y, img, skill):
self.x = x
self.y = y
self.speed_x = speed_x
self.speed_y = speed_y
self.img = img
mask = np.zeros_like(img)
mask[img > 0] = 1
self.mask = mask
self.h, self.w = img.shape[:2]
self.skill = skill
def move(self, screen, checkimg):
global GM
global llock
# print(llock)
if not llock:
self.x += self.speed_x
self.y += self.speed_y
if self.x > W - self.w/2 or self.x < self.w/2:
self.speed_x = -self.speed_x
if self.y > H - self.h/2 or self.y < self.h/2:
self.speed_y = -self.speed_y
t, l, b, r, tt, tl, tb, tr = getPIXEL(self.x, self.y, self.w/2, self.h/2)
ctimg = checkimg[t:b,l:r]
stimg = screen[t:b,l:r]
if np.sum(ctimg[self.mask[tt:tb,tl:tr]>0]) > 0:
self.skill.trigger()
if self.skill.finish is False:
GM.appendskill(self.skill)
return True
else:
screen[t:b,l:r] = screen[t:b,l:r] * (1 - self.mask[tt:tb,tl:tr]) + self.mask[tt:tb,tl:tr] * self.img[tt:tb,tl:tr]
return False
个人简介
百度飞桨开发者技术专家 PPDE
百度飞桨官方帮帮团、答疑团成员
国立清华大学18届硕士
以前不懂事,现在只想搞钱~欢迎一起搞哈哈哈
我在AI Studio上获得至尊等级,点亮9个徽章,来互关呀!!!
https://aistudio.baidu.com/aistudio/personalcenter/thirdview/311006
B站ID: 玖尾妖熊