【AI创造营】决战二仙桥(DodgeFace-EXQver)是款基于人脸检测的躲避类游戏,优化了技术与模型,适配普通配置电脑。玩家需通过移动身体、转动头部躲避谭警官,未检测到脸即Game Over,死亡后按r重开。可通过--level X调整难度,新增谭谈交通宇宙元素,气球哥和强人锁男哥等NPC会出现并释放特殊技能。
☞☞☞AI 智能聊天, 问答助手, AI 智能搜索, 免费无限量使用 DeepSeek R1 模型☜☜☜

python erxianqiao_map_skill.py
python erxianqiao_map_skill.py --level X
#封装了一下检测模块,让视频流的检测更稳定一点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以上就是【AI创造营】决战二仙桥的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号