增加配置对应
This commit is contained in:
@@ -69,28 +69,42 @@ def run_automation_for_group(group_index):
|
||||
v = group['move_velocity'] # 从配置读取移动速度
|
||||
|
||||
def yolo_shibie(im_PIL, detections, model):
|
||||
results = model(im_PIL)
|
||||
for result in results:
|
||||
for i in range(len(result.boxes.xyxy)):
|
||||
left, top, right, bottom = result.boxes.xyxy[i]
|
||||
scalar_tensor = result.boxes.cls[i]
|
||||
value = scalar_tensor.item()
|
||||
label = result.names[int(value)]
|
||||
if label == 'center' or label == 'next' or label == 'boss' or label == 'zhaozi':
|
||||
player_x = int(left + (right - left) / 2)
|
||||
player_y = int(top + (bottom - top) / 2) + 30
|
||||
RW = [player_x, player_y]
|
||||
detections[label] = RW
|
||||
elif label == 'daojv' or label == 'gw':
|
||||
player_x = int(left + (right - left) / 2)
|
||||
player_y = int(top + (bottom - top) / 2) + 30
|
||||
RW = [player_x, player_y]
|
||||
detections[label].append(RW)
|
||||
elif label == 'npc1' or label == 'npc2' or label == 'npc3' or label == 'npc4':
|
||||
player_x = int(left + (right - left) / 2)
|
||||
player_y = int(bottom) + 30
|
||||
RW = [player_x, player_y]
|
||||
detections[label] = RW
|
||||
try:
|
||||
results = model(im_PIL)
|
||||
for result in results:
|
||||
if result.boxes is None or len(result.boxes.xyxy) == 0:
|
||||
continue
|
||||
for i in range(len(result.boxes.xyxy)):
|
||||
try:
|
||||
left = float(result.boxes.xyxy[i][0])
|
||||
top = float(result.boxes.xyxy[i][1])
|
||||
right = float(result.boxes.xyxy[i][2])
|
||||
bottom = float(result.boxes.xyxy[i][3])
|
||||
cls_id = int(result.boxes.cls[i])
|
||||
label = result.names[cls_id]
|
||||
|
||||
if label == 'center' or label == 'next' or label == 'boss' or label == 'zhaozi':
|
||||
player_x = int(left + (right - left) / 2) + 3
|
||||
player_y = int(top + (bottom - top) / 2) + 40
|
||||
RW = [player_x, player_y]
|
||||
detections[label] = RW
|
||||
elif label == 'daojv' or label == 'gw':
|
||||
player_x = int(left + (right - left) / 2) + 3
|
||||
player_y = int(top + (bottom - top) / 2) + 40
|
||||
RW = [player_x, player_y]
|
||||
if label not in detections:
|
||||
detections[label] = []
|
||||
detections[label].append(RW)
|
||||
elif label == 'npc1' or label == 'npc2' or label == 'npc3' or label == 'npc4':
|
||||
player_x = int(left + (right - left) / 2)
|
||||
player_y = int(bottom) + 30
|
||||
RW = [player_x, player_y]
|
||||
detections[label] = RW
|
||||
except Exception as e:
|
||||
print(f"⚠️ 处理检测框时出错: {e}")
|
||||
continue
|
||||
except Exception as e:
|
||||
print(f"⚠️ YOLO检测出错: {e}")
|
||||
return detections
|
||||
|
||||
def sq(p1, p2):
|
||||
|
||||
Reference in New Issue
Block a user