代码拉取完成,页面将自动刷新
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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。