What does OpenCV's cvWaitKey( ) function do?

2019-01-03 10:28发布

What happens during the execution of cvWaitKey()? What are some typical use cases? I saw it in OpenCV reference but the documentation isn't clear on its exact purpose.

标签: c++ c opencv
9条回答
我欲成王,谁敢阻挡
2楼-- · 2019-01-03 10:55

cvWaitKey(0) stops your program until you press a button.

cvWaitKey(10) doesn't stop your program but wake up and alert to end your program when you press a button. Its used into loops because cvWaitkey doesn't stop loop.

Normal use

char k;

k=cvWaitKey(0);

if(k == 'ESC')

with k you can see what key was pressed.

查看更多
家丑人穷心不美
3楼-- · 2019-01-03 10:56

. argument of 0 is interpreted as infinite

. in order to drag the highGUI windows, you need to continually call the cv::waitKey() function. eg for static images:

cv::imshow("winname", img);

while(cv::waitKey(1) != 27); // 27 = ascii value of ESC

查看更多
我欲成王,谁敢阻挡
4楼-- · 2019-01-03 10:59

Plain simply, cvWaitKey() sleeps for X miliseconds, waiting for any key to be pressed.

int cvWaitKey(int X);

If a key is pressed, this function returns the ASCII code of key. Or returns -1 if no keys were pressed during that time.

查看更多
登录 后发表回答