Я хочу использовать ее в Python exe.
Вот мой код ниже:
Код: Выделить всё
try:
import time
import cv2
import mss
import numpy as np
from ultralytics import YOLO
import math
import os
import sys
def screen_capture():
with mss.mss() as sct:
monitor = sct.monitors[2]
sct_img = sct.grab(monitor)
frame = np.array(sct_img)
frame = cv2.cvtColor(frame, cv2.COLOR_BGRA2BGR)
return frame
def detect_realtime(model):
while True:
frame = screen_capture()
results = model(frame,device="cpu")
highest_conf = 0
best_box = None
for r in results:
boxes = r.boxes
for box in boxes:
conf = box.conf[0]
if conf > highest_conf:
highest_conf = conf
best_box = box
if best_box:
x1, y1, x2, y2 = best_box.xyxy[0]
x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)
cls_id = int(best_box.cls[0])
conf = math.ceil(highest_conf * 100) / 100
cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 255, 0), 2)
cv2.putText(frame, f'{model.names[cls_id]} {conf:.2f}', (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2)
print([(x1+x2)//2, (y1+y2)//2])
resized_frame = cv2.resize(frame, (1366, 768))
cv2.imshow('YOLO Realtime Detection', resized_frame)
cv2.moveWindow('YOLO Realtime Detection', 2000, 100)
if cv2.waitKey(500) == ord('q'):
break
cv2.destroyAllWindows()
if __name__ == '__main__':
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
print(base_path)
anvil_model= os.path.join(base_path,'best.pt')
model = YOLO(anvil_model)
detect_realtime(model)
except Exception as e:
time.sleep(5555)
pyinstaller --onefile --add-data "best.pt;." main.py
Консоль написала эту ошибку:
[Errno 2] Нет такого файла или каталога: 'C:\Users\User\AppData\Local\Temp\_MEI119602\ultralytics \cfg\default.yaml'
Я искал проблемы YOLOv8, нашел две проблемы ниже, но решения нет.
https:/ /github.com/ultralytics/ultralytics/issues/7143
https://github.com/ultralytics/ultralytics/issues/1158
- -onedir для меня не решение. Мне нужен один exe-файл, который может работать на других компьютерах.
Что мне нужно сделать?
Подробнее здесь: https://stackoverflow.com/questions/779 ... er-onefile