暂停时编辑轨道栏值

时间:2012-05-04 09:07:19

标签: c++ opencv

在下面的代码中,我创建了一个循环,一直运行直到'q'被按下。我正在使用轨迹栏来设置2个变量。但是我想创建某种暂停来设置这些跟踪条,然后再运行这个循环。然而,getch()函数会冻结整个程序,直到我按下一个键并且不允许我编辑轨迹栏。是否可以创建某种暂停,允许我编辑轨迹栏?

int main(int argc, const char * argv[])
{
    cvNamedWindow("test image", CV_WINDOWS_AUTOSIZE);
    cvCreateTrackbar("subject", "test image", &subjectID, 40, NULL);
    cvCreateTrackbar("subject", "test image", &photoID, 10, NULL);
    ...
    <some more code>
    ...

    while(key != 'q')
    {
        cout << "set trackbars and press enter";
        getch()
        ...
        <and more code>
        ...
    }
}

1 个答案:

答案 0 :(得分:1)

另一个while循环和cv :: waitKey()应该可以解决问题。

cout << "set trackbars and press enter"; //you might want to put this inside the loop
while (true) {
            int c = waitKey(10);
            if( c == 13) { break; } 
        }

while(key != 'q')
{
    ...
    /*all your code*/
    ...
}