我正在尝试根据他们的衣服在实时视频中检测到人,并且需要将速度从每秒11帧提高到每秒30帧(FPS)或更高。不幸的是,它要求至少30 FPS才能正常工作。
有什么方法可以加快速度吗?
[当我训练模型时,我遵循了使用HOG + SVM的blog
注意:我有GPU(1050)
培训后的完整代码:
import cv2
import dlib
from imutils.video import FPS
detector = dlib.simple_object_detector("clothes_detector.svm")
cap = cv2.VideoCapture(0)
fps = FPS().start()
while (1):
_, image = cap.read()
if _ is True:
# convert to grayscale
image =cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
else:
continue
# hog_image = detector.detect(image, annotate='texture')
boxes = detector(img)
for box in boxes:
(x, y, xb, yb) = [box.left(), box.top(), box.right(), box.bottom()]
cv2.rectangle(image, (x, y), (xb, yb), (0, 0, 255), 2)
cv2.imshow("Color Tracking", img)
# cv2.imshow("kernel", g_kernel)
if cv2.waitKey(1) & 0xFF == ord('q'):
cap.release()
cv2.destroyAllWindows()
break
fps.update()
fps.stop()
# print("[INFO] elapsed time: {:.2f}".format(fps.elapsed()))
print("[INFO] approx. FPS: {:.2f}".format(fps.fps()))
直白地说,您需要在dlib上进行更多的练习。我相信这会帮助您:https://www.pyimagesearch.com/2017/02/06/faster-video-file-fps-with-cv2-videocapture-and-opencv/