gpt4 book ai didi

c - 带视频的opencv圆检测

转载 作者:太空宇宙 更新时间:2023-11-03 23:03:35 24 4
gpt4 key购买 nike

有没有办法等到某些事情发生(while 循环)或等待 10 秒后再进行圆圈检测,但仍显示视频。我已经用 while 循环试过了,但如果不满足条件,帧将不会显示,因为代码没有得到 cvShow\iamge()。

最佳答案

是的,这是可能的,但您必须使用线程。声明一个全局变量 bool exec_circle_detection = false; 并启动第二个线程。在此线程上,调用 sleep(10) 等待 10 秒,然后将 exec_circle_detection 更改为 true

在主线程中,在帧抓取循环内,检查 bool 变量是否设置为 true,如果不是,则不会处理帧。这部分看起来像这样(在 C 中):

char key = 0;
while (key != 27) // ESC
{
frame = cvQueryFrame(capture);
if (!frame)
{
fprintf( stderr, "!!! cvQueryFrame failed!\n" );
break;
}

if (exec_circle_detection)
{
// execute custom processing
}

// Display processed frame
cvShowImage("result", frame);

// Exit when user press ESC
key = cvWaitKey(10);
}

如果您计划每 10 秒进行一次圆检测,则需要在执行自定义处理后将 exec_circle_detection 更改为 false。在辅助线程上,调整您的代码,使 while 循环每 10 秒将 exec_circle_detection 更改为 true。

关于c - 带视频的opencv圆检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9480240/

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