1

我正在运行一个 opencv 程序以从实时视频中获取一些 x 和 y 坐标。在后台运行程序而不打开任何 cv2 窗口来获取坐标是行不通的,程序会立即终止。当我通过打开任何 cv2 窗口运行时,程序运行完美。

4

1 回答 1

0

我会支持 iGian 的回答。请发布一些代码。

根据您的描述,我假设您的 OpenCV 计算以某种方式在不阻塞主线程的单独线程中运行。所以会发生什么:

- main thread -> start calculation thread
- main thread -> I'm finished, shut everything down including the calculation thread

现在,当您从主线程执行 cv.imshow() 和 cv.waitkey() 之类的操作时,它看起来像这样:

- main thread -> start calculation thread
- main thread -> wait for a key to be pressed
- calculation thread -> keep calculating
- ...
- ...
- main thread -> "a key has been pressed"
- main thread -> I'm finished, shut everything down including the calculation thread

但这是一个相当盲目的猜测,因为我们需要你的代码来看看到底发生了什么。上述场景的解决方案是让主线程等待直到满足条件 - 例如计算线程发送事件或写入条件变量。

于 2019-02-10T13:04:31.870 回答