个人公众号
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/53c2413cba67f18f74da67339177257e.jpeg#pic_center)
参考链接
opencv调用yoloV4
import cv2 as cv
import time
net = cv.dnn_DetectionModel('hand_v4-tiny.cfg', 'hand_v4-tiny_30000.weights')
net.setInputSize(416, 416)
net.setInputScale(1.0 / 255)
net.setInputSwapRB(True)
frame = cv.imread('imgs/69.jpg')
with open('hand.names', 'rt') as f:
names = f.read().rstrip('\n').split('\n')
print(names)
startTime = time.time()
classes, confidences, boxes = net.detect(frame, confThreshold=0.2, nmsThreshold=0.25)
endTime = time.time()
print("Time: {}s".format(endTime-startTime))
for classId, confidence, box in zip(classes.flatten(), confidences.flatten(), boxes):
label = '%.2f' % confidence
label = '%s: %s' % (names[classId], label)
labelSize, baseLine = cv.getTextSize(label, cv.FONT_HERSHEY_SIMPLEX, 0.5, 1)
left, top, width, height = box
top = max(top, labelSize[1])
cv.rectangle(frame, box, color=(0, 255, 0), thickness=3)
cv.rectangle(frame, (left, top - labelSize[1]), (left + labelSize[0], top + baseLine), (255, 255, 255), cv.FILLED)
cv.putText(frame, label, (left, top), cv.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0))
cv.imshow('out', frame)
cv.waitKey(0)