Overview of cvwaitkey (k)

Source: Internet
Author: User

 
 

The development environment of the author is vs's MFC framework, and image processing is carried out in combination with opencv1.0. There may be a lot of initial development like the author himselfProgramMembers will use cvwaitkey (), but they have a thorough understanding of cvwaitkey (), which may cause some confusion in specific development. After querying some information, the information is summarized as follows:
The Reference URL is as follows:
Http://zhidao.baidu.com/question/113288896
Http://www.opencv.org.cn/forum/viewtopic.php? F = 1 & t = 3324 & START = 0
Http://www.google.com.hk/search? Hl = ZH-CN & inlang = ZH-CN & newwindow = 1 & Safe = strict & client = aff-cs-360se & HS = KLG & Q = % E4 % B8 % 80% E7 % A7 % 92% E5 % Ba % 94% E8 % af % a5 % E8 % be % 93% E5 % 87% Ba % E5 % A4 % 9A % E5 % B0 % 91% E5 % B8 % A7 % ef % BC % 9f & OQ = % E4 % B8 % 80% E7 % A7 % 92% E5 % Ba % 94% E8 % af % a5 % E8 % be % 93% E5 % 87% Ba % E5 % A4 % 9A % E5 % B0 % 91% E5 % B8 % A7 % EF % BC % 9f & AQ = F & AQI = & AQL = & gs_sm = E & gs_upl = signature. 4.3l8l0

First, in cvwaitkey (k), the unit of K is millisecond, 1000 milliseconds equals 1 second. At the same time, according to the data description, when the image is displayed, when 27 or 28 frames are displayed per second, the video we see is smooth. Based on my experiments and observations, if I play 25 frames of video per second, the video is still smooth. For 25 frames at the same time, K = 1000/25 = 40. That is, after a frame is not processed, the program will wait 40 milliseconds to read the next frame. In the materials, K in cvwaitkey () in MFC is useless, but K is normal in the author's program. Although I do not quite understand the principle, if you encounter the same problem, you can try this way.
For more information about cvwaitkey (), refer to the interpretation of the opencv Chinese Forum:

Source code of cvwaitkey in Windows:

Cv_impl intcvwaitkey (INT delay) {int time0 = gettickcount (); For (;) {cvwindow * window; MSG message; int is_processed = 0; if (delay> 0 & ABS (INT) (gettickcount ()-time0)> = delay) | hg_windows = 0) Return-1; if (delay <= 0) getmessage (& message, 0, 0, 0); else if (peekmessage (& message, 0, 0, 0, pm_remove) = false) {sleep (1); continue;} For (window = hg_windows; window! = 0 & is_processed = 0; window = Window-> next) {If (window-> hwnd = message. hwnd | window-> frame = message. hwnd) {is_processed = 1; Switch (message. message) {Case wm_destroy: Case wm_char: dispatchmessage (& message); Return (INT) message. wparam; Case wm_keydown: translatemessage (& message); default: dispatchmessage (& message); is_processed = 1; break ;}} if (! Is_processed) {translatemessage (& message); dispatchmessage (& message );}}}


It can be seen that in addition to sleep, cvwaitkey also has important message processing, such as keyboard messages and characters .... this message processing structure should be familiar to those who have written Windows programs.

You can make an extreme assumption:

If there is no cvwaitkey, the execution time of each command in the loop is 0.0000000001 s, which is close to 0. therefore, capture may have 10000 frames of images, and 10000 frames of images need to be played after seconds. As a result, you have not seen the screen, and the screen is black ....

The above is a summary of the three web pages. Hope to help you

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.