Ai
1 Star 0 Fork 0

BG8CFB/YOLOV7_API

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
demo_run_API.py 2.22 KB
一键复制 编辑 原始数据 按行查看 历史
BG8CFB 提交于 2023-12-17 11:53 +08:00 . 初始化
import time
import cv2
import torch
import detect_with_API
cap = cv2.VideoCapture(r'D:\Downloads\Video\1080p.mp4') # 0
DETECT_API = detect_with_API.detectapi(weights='models/yolov7.pt')
init_data = {
'debug': False
}
def run_time(fun):
def wrapper(*args, **kwargs):
t1 = time.time()
ret_val = fun(*args, **kwargs)
t2 = time.time()
print('Time elapsed was: {}'.format(t2 - t1))
return ret_val
return wrapper
def detect_video(video_file):
# 视频检测
cap = cv2.VideoCapture(video_file)
rec, img = cap.read()
result, names = a.detect([img])
img = result[0][0] # 每一帧图片的处理结果图片
# 每一帧图像的识别结果(可包含多个物体)
for cls, (x1, y1, x2, y2), conf in result[0][1]:
print(names[cls], x1, y1, x2, y2, conf) # 识别物体种类、左上角x坐标、左上角y轴坐标、右下角x轴坐标、右下角y轴坐标,置信度
'''
cv2.rectangle(img,(x1,y1),(x2,y2),(0,255,0))
cv2.putText(img,names[cls],(x1,y1-20),cv2.FONT_HERSHEY_DUPLEX,1.5,(255,0,0))'''
print() # 将每一帧的结果输出分开
cv2.imshow("vedio", img)
if cv2.waitKey(1) == ord('q'):
break
def detect_img(ImgPath):
images = cv2.imread(ImgPath + '\\' + img_name)
images, result = DETECT_API.detect(images)
def debug_detect():
pass
if __name__ == '__main__':
with torch.no_grad():
while True:
rec, img = cap.read()
result, names = a.detect([img])
img = result[0][0] # 每一帧图片的处理结果图片
# 每一帧图像的识别结果(可包含多个物体)
for cls, (x1, y1, x2, y2), conf in result[0][1]:
print(names[cls], x1, y1, x2, y2, conf) # 识别物体种类、左上角x坐标、左上角y轴坐标、右下角x轴坐标、右下角y轴坐标,置信度
'''
cv2.rectangle(img,(x1,y1),(x2,y2),(0,255,0))
cv2.putText(img,names[cls],(x1,y1-20),cv2.FONT_HERSHEY_DUPLEX,1.5,(255,0,0))'''
print() # 将每一帧的结果输出分开
cv2.imshow("vedio", img)
if cv2.waitKey(1) == ord('q'):
break
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/bg8cfb/yolov7_api.git
git@gitee.com:bg8cfb/yolov7_api.git
bg8cfb
yolov7_api
YOLOV7_API
master

搜索帮助