首页 > 解决方案 > 从视频流中执行接近实时的人员检测的问题

问题描述

目标:从给定的远程视频流中以最小的延迟/延迟实时检测人。

设置 :

我目前有基本功能工作,但是,它似乎相当慢。当我需要在不到一秒的时间内处理图像时,大约每隔几秒钟就会处理一次图像。所以结果是一个视频,它显示了流后面的更新方式并且断断续续。通过四处搜索,这似乎是一个常见问题,但我似乎还没有找到一个直接的答案。

正如一些论坛所说,我已经将流抓取实现为自己的线程,但我相信现在的问题只是处理抓取的图像所需的时间。

是否可以提高性能?我是否需要在提供良好 GPU 的系统上在云中进行此处理,以便我可以利用这种性能提升?我是否使用了错误的 yolo 权重和 cfg?我知道 yolov3 已经出局了,但我认为我在使用我的环境时遇到了问题。

incoming_frames = queue.Queue()

class Stream(threading.Thread):
    def __init__(self, ID):
        threading.Thread.__init__(self)
        self.cam=cv2.VideoCapture('http://raspberrypi.local:5000/')

    def run(self):
        frame_id = 0
        while True:
            ret,frame=self.cam.read()
            if ret:
                frame_id = frame_id + 1
                frame_dict = {}
                frame_dict['frame'] = frame
                frame_dict['id'] = frame_id
                incoming_frames.put(frame_dict)
                print("ACQUIRED FRAME " + str(frame_id))
                time.sleep(0.1)
    def stop(self):
        self._stop_event.set()

print("[INFO] Starting Process......")

print("[INFO] Load Model / Weights")
options = {"model": "cfg/yolo.cfg", "load": "bin/yolo.weights", "threshold": 0.1}
tfnet = TFNet(options)

print("[INFO] Start Video Grab Thread")
stream = Stream(0)
stream.start()


while True:
    if(not incoming_frames.empty()):
        frame = incoming_frames.get()
        result = tfnet.return_predict(frame['frame'])
        print("Processing Frame " + str(frame['id']))
        coordinates = []
        for detection in result:
            if detection['label'] == 'person' and detection['confidence'] >= 0.4:
                cv2.rectangle(frame['frame'], (detection['topleft']['x'], detection['topleft']['y']),
                   (detection['bottomright']['x'], detection['bottomright']['y']),
                    (0, 255, 0), 2)
                body = {'x': detection['topleft']['x'], 'y': detection['topleft']['y'],
                        'width': (detection['bottomright']['x'] - detection['topleft']['x']),
                        'height': (detection['bottomright']['y'] - detection['topleft']['y'])}
                coordinates.append(body)
        cv2.rectangle(frame['frame'], frame['x1'], frame['y1'], frame['x2'], frame['y2'], (0, 255, 0), 2)
        cv2.imshow('Video', frame['frame'])
        cv2.waitKey(1)

stream.stop()
cv2.destroyAllWindows()

标签: pythonopencvyolodarknetdarkflow

解决方案


推荐阅读