当前位置:网站首页>Deploy yolov7 target detection using OpenCV and onnxruntime - record post
Deploy yolov7 target detection using OpenCV and onnxruntime - record post
2022-07-19 05:46:00 【Just do it! ට⋆*】
I want to realize these two days yolov5 Of tensort Speed up , A little white , Very shallow understanding , Only record , Prevent forgetting .
Take a note of it yolov7:
yolov7 Of OpenCV、ONNXRuntime Deploy
Share the open source works of the boss yolov7 Of OpenCV、ONNXRuntime Deploy
The boss not only realized yolov7 Of OpenCV、ONNXRuntime Deploy , And selflessly contributed to the transformation model , Thank you very much .
ONNXRuntime Deploy
be based on gpu function , Pretty fast , It can be done in real time .
Running steps : Download the model file and put it in yolov7-opencv-onnxrun-cpp-py-main Under the table of contents
cd yolov7-opencv-onnxrun-cpp-py-main
mikdir simples # Put in a few pictures and videos
# function
python onnxruntime/main.py --imgpath simples/1.jpg --modelpath models/yolov7-tiny_384x640.onnx
result 
Add video stream reasoning
On the basis of the source code, the reasoning of video stream and reasoning for a certain class are added , The code is as follows :
VID_FORMATS = ['asf', 'avi', 'gif', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'wmv'] # include video suffixes
imgpath = args.imgpath
print(imgpath.split('.')[-1])
if imgpath.split('.')[-1] in VID_FORMATS:
cap =cv2.VideoCapture(imgpath)
while True:
success, srcimg = cap.read()
srcimg = imutils.resize(srcimg, width=640)
t1 = time.time()
boxes, scores, class_ids = yolov7_detector.detect(srcimg)
print(time.time() - t1)
# Draw detections
dstimg = yolov7_detector.draw_detections(srcimg, boxes, scores, class_ids)
print(time.time() - t1)
winName = 'Deep learning object detection in OpenCV'
cv2.namedWindow(winName, 0)
cv2.imshow(winName, dstimg)
cv2.waitKey(1)
cv2.destroyAllWindows()
else:
srcimg = cv2.imread(args.imgpath)
# Detect Objects
t1 = time.time()
boxes, scores, class_ids = yolov7_detector.detect(srcimg)
print(time.time() - t1)
# Draw detections
dstimg = yolov7_detector.draw_detections(srcimg, boxes, scores, class_ids)
print(time.time() - t1)
winName = 'Deep learning object detection in OpenCV'
cv2.namedWindow(winName, 0)
cv2.imshow(winName, dstimg)
cv2.waitKey(0)
cv2.destroyAllWindows()
Modify the reading method of the input source , Add to mp4 Input support for , Add the detection of specified classes in the code
def draw_detections(self, image, boxes, scores, class_ids):
for box, score, class_id in zip(boxes, scores, class_ids):
x1, y1, x2, y2 = box.astype(int)
# Draw rectangle
#id Corresponding coconame Sort files by category , Specify identifying pedestrians
if class_id==0:
cv2.rectangle(image, (x1, y1), (x2, y2), (0, 0, 255), thickness=2)
label = self.class_names[class_id]
label = f'{
label} {
int(score * 100)}%'
labelSize, baseLine = cv2.getTextSize(label, cv2.FONT_HERSHEY_SIMPLEX, 0.5, 1)
# top = max(y1, labelSize[1])
# cv.rectangle(frame, (left, top - round(1.5 * labelSize[1])), (left + round(1.5 * labelSize[0]), top + baseLine), (255,255,255), cv.FILLED)
cv2.putText(image, label, (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), thickness=2)
return image
give the result as follows 
Running speed comparison
All adopt yolov7-tiny_384x640.onnx Model
opencv-cpu inference time:1.04 s
ONNXRuntime-gpu inference time:0.17 s
yolov5
边栏推荐
- 关于AS安装之后的一些细碎事项
- SGM: Sequence Generation Model for Multi-Label Classification(用于多标签分类的序列生成模型)
- Class file format understanding
- Review my first job search trip
- 写一个定时自检
- Pointnet++ code explanation (III): query_ ball_ Point function
- Parsing bad JSON data using gson
- Transform the inriapearson data set into Yolo training format and visualize it
- Flutter Intl的使用
- CV-Model【2】:Alexnet
猜你喜欢

Pointnet++代码详解(七):PointNetSetAbstractionMsg层

MySQL learning notes (5) -- join join table query, self join query, paging and sorting, sub query and nested query

Wxml template syntax in wechat applet
![[first launch in the whole network] will an abnormal main thread cause the JVM to exit?](/img/ae/5df25d64c2f29292bbfb21f696bbb0.png)
[first launch in the whole network] will an abnormal main thread cause the JVM to exit?

VS 中 error C4996: ‘scanf‘: This function or variable may be unsafe. 的解决方法。

微信小程序的自定义组件

【语音识别】MFCC特征提取

软件过程与管理总复习

记录:YOLOv5模型剪枝轻量化

Pointnet++ code details (II): Square_ Distance function
随机推荐
Preorder, middle order and postorder traversal of binary tree
[first launch in the whole network] will an abnormal main thread cause the JVM to exit?
模型时间复杂度和空间复杂度
Hanoi Tower problem -- > recursive implementation
Page navigation of wechat applet
Pointnet++代码详解(六):PointNetSetAbstraction层
CV-Model【2】:Alexnet
PyTorch学习笔记【5】:使用卷积进行泛化
MySQL transactions
关于线程池中终止任务
利用IDE打jar包
MySQL queries the data of the current day, this week, this month and last month
对比学习用于图像语义分割(两篇文章)
Custom components of wechat applet
使用OpenCV、ONNXRuntime部署YOLOV7目标检测——记录贴
记录:YOLOv5模型剪枝轻量化
关于AS安装之后的一些细碎事项
Application and principle of throttle/debounce
Edge AI edge Intelligence: Communication EF "city edge ai: algorithms and systems (to be continued)
Pointnet++ code details (II): Square_ Distance function