gpt4 book ai didi

Object detection from multiple sources(来自多个源的目标检测)

转载 作者:bug小助手 更新时间:2023-10-25 17:55:14 25 4
gpt4 key购买 nike



I have initiated a single object detection model using the coco ssd.
I am trying to detect objects from 2 different cameras

我已经使用Coco SSD启动了一个单目标检测模型。我正在试着从两个不同的摄像头检测物体


THE LOGIC OF THE CODE:-

代码的逻辑是:-


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

using this approach in neither of the video frames the correct objects are detected
OUTPUT
The above image shows the output i am getting.
with a single thread it works fine but if i try running more than one thread then it starts producing such errors for all video sources.
why is this happening???
what might be the solution?

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


更多回答

Can you share a minimal example that reproduces your issue?

你能分享一个重现你的问题的最小例子吗?

优秀答案推荐

Depending how your actual code handles race conditions, you should try using two separate instances of your model, one for each thread. Something like:

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


model1=cv2.dnn_DetectionModel(weightsPath,configPath)
model2=cv2.dnn_DetectionModel(weightsPath,configPath)

更多回答

Actually the number of threads are not defined. The threads are created dynamically. so for each thread i can't create an individual model. Is there any other way around?

实际上,线程的数量并没有定义。线程是动态创建的。因此,我不能为每个线程创建单独的模型。附近有没有别的路?

This really depends on the details. Can you share your actual code instead of just a sketch of the logic?

这真的取决于细节。你能分享你的实际代码,而不只是逻辑的草图吗?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com