多源物体检测

问题描述 投票:0回答:1

我已经使用 coco ssd 启动了单个对象检测模型。 我正在尝试从 2 个不同的相机检测物体

代码逻辑:-

model=cv2.dnn_DetectionModel(weightsPath,configPath)
cam1=cv2.VideoCapture(0)
cam1=cv2.VideoCapture(1)

#thread 1
while true:
    success1,img1 = cam1.read()
    result1=model.detect(img1)
    cv2.imshow("result1", result1)
    if cv2.waitKey(2) & 0xFF==ord('x'):
        break

#thread 2 
while true:
    success2,img2 = cam2.read()
    result2=model.detect(img2)
    cv2.imshow("result2", result2)
    if cv2.waitKey(2) & 0xFF==ord('x'):
        break

在两个视频帧中使用这种方法都无法检测到正确的对象 上图显示了我得到的输出。 使用单个线程它工作正常,但如果我尝试运行多个线程,那么它就会开始为所有视频源产生此类错误。 为什么会这样??? 解决方案可能是什么?

python image-processing object-detection opencv3.0 yolo
1个回答
0
投票

根据实际代码处理竞争条件的方式,您应该尝试使用模型的两个单独的实例,每个线程一个。比如:

model1=cv2.dnn_DetectionModel(weightsPath,configPath)
model2=cv2.dnn_DetectionModel(weightsPath,configPath)
© www.soinside.com 2019 - 2024. All rights reserved.