-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
44 lines (36 loc) · 1.15 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import os
os.environ['KMP_DUPLICATE_LIB_OK']='True'
import cv2
import time
import ctypes
from dector_trt import Detector
import pycuda.autoinit
def detect(engine_file_path):
detector = Detector(engine_file_path)
capture = cv2.VideoCapture(0)
# capture = cv2.VideoCapture(0)
fps = 0.0
while True:
ret, img = capture.read()
if img is None:
print('No image input!')
break
t1 = time.time()
result_img = detector.detect(img)
fps = (fps + (1. / (time.time() - t1))) / 2
cv2.putText(result_img, 'FPS: {:.2f}'.format(fps), (50, 30), 0, 1, (0, 255, 0), 2)
cv2.putText(result_img, 'Time: {:.3f}'.format(time.time() - t1), (50, 60), 0, 1, (0, 255, 0), 2)
if ret == True:
cv2.imshow('frame', result_img)
if cv2.waitKey(5) & 0xFF == ord('q'):
break
else:
break
capture.release()
cv2.destroyAllWindows()
detector.destroy()
if __name__ == '__main__':
PLUGIN_LIBRARY = "weights/libmyplugins.so"
ctypes.CDLL(PLUGIN_LIBRARY)
engine_file_path = 'weights/yolov5s.engine'
detect(engine_file_path)