33 lines
993 B
Python
33 lines
993 B
Python
|
# 串口通信
|
||
|
import serial
|
||
|
import time
|
||
|
import threading
|
||
|
import torch
|
||
|
import cv2
|
||
|
|
||
|
class yolo_class(threading.Thread):
|
||
|
def __init__(self,yolo_path):
|
||
|
threading.Thread.__init__(self)
|
||
|
self.yolo_path = yolo_path
|
||
|
self.model = torch.hub.load('ultralytics/yolov5', 'custom',
|
||
|
path=yolo_path, force_reload=True)
|
||
|
def run(self):
|
||
|
self.model = torch.hub.load('ultralytics/yolov5', 'custom',
|
||
|
path=self.yolo_path, force_reload=True)
|
||
|
self.flag = False
|
||
|
print('權重完成')
|
||
|
while True:
|
||
|
if self.flag == True:
|
||
|
print(f'yolo_run_2')
|
||
|
self.results = self.model(self.img, size=1280)
|
||
|
self.flag = False
|
||
|
time.sleep(0.05)
|
||
|
|
||
|
|
||
|
def YoloDetect(self,img):
|
||
|
self.results = self.model(img,size=1280)
|
||
|
# print(f'yolo_run')
|
||
|
# self.img = img
|
||
|
# self.flag = True
|
||
|
return self.results
|