加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
FishYOLONode.py 1.31 KB
一键复制 编辑 原始数据 按行查看 历史
ctguhzy 提交于 2024-12-03 11:18 . Updated.
import torch
import cv2
import os
import numpy as np
from ultralytics import YOLO
from threading import Thread
import logging
from nodes.Node import Node
from nodes.YOLONode import YOLONode
import time
from multiprocessing import Process, Queue
from nodes.SORTTrackNode import SORTTrackNode
class FishYOLONode(YOLONode):
def __init__(self,name="FishYOLONode",parent=None):
super().__init__(name, parent)
def run(self):
device = torch.device("cuda:0")
torch.cuda.set_device(device)
self.open()
self.is_stopped = False
while True:
if self.is_stopped:
if self.is_opened:
self.close()
break
else:
if( not self._framePool.empty()):
#try:
xtime = time.time()
frame,videoIndex,frameIndex = self._framePool.get()
#print("video Index:", videoIndex)
results = self.model(frame,imgsz=640,device=0)
endTime = time.time()
elapsedTime = endTime - xtime
#print(f"YoloTime:{ elapsedTime }")
if frame is not None:
self.passFrame([frame, videoIndex, frameIndex, results[0].boxes.cpu().numpy()])
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化