In 18.04 opencv waitKey loop exit immediately











up vote
0
down vote

favorite












I have compiled and linked example from Example source
Successfully. In Ubuntu 16.03 begin to work after entering user to group video.
I did the same in 18.04 but program exits immediately.



I try to debug code and discovered that problem is waitKey.
If i change



if(waitKey(30) >= 0) break;


to



waitKey(30);


It works, but not correctly. How to correctly change the code?










share|improve this question




















  • 1




    "It works, but not correctly." - please elaborate. If I read the documentation [1] correctly, waitKey waits for x ms on key press. If no key is pressed it returns -1 and loop in your example breaks... [1] docs.opencv.org/3.1.0/d7/dfc/…
    – honza-kasik
    Nov 24 at 17:03















up vote
0
down vote

favorite












I have compiled and linked example from Example source
Successfully. In Ubuntu 16.03 begin to work after entering user to group video.
I did the same in 18.04 but program exits immediately.



I try to debug code and discovered that problem is waitKey.
If i change



if(waitKey(30) >= 0) break;


to



waitKey(30);


It works, but not correctly. How to correctly change the code?










share|improve this question




















  • 1




    "It works, but not correctly." - please elaborate. If I read the documentation [1] correctly, waitKey waits for x ms on key press. If no key is pressed it returns -1 and loop in your example breaks... [1] docs.opencv.org/3.1.0/d7/dfc/…
    – honza-kasik
    Nov 24 at 17:03













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have compiled and linked example from Example source
Successfully. In Ubuntu 16.03 begin to work after entering user to group video.
I did the same in 18.04 but program exits immediately.



I try to debug code and discovered that problem is waitKey.
If i change



if(waitKey(30) >= 0) break;


to



waitKey(30);


It works, but not correctly. How to correctly change the code?










share|improve this question















I have compiled and linked example from Example source
Successfully. In Ubuntu 16.03 begin to work after entering user to group video.
I did the same in 18.04 but program exits immediately.



I try to debug code and discovered that problem is waitKey.
If i change



if(waitKey(30) >= 0) break;


to



waitKey(30);


It works, but not correctly. How to correctly change the code?







18.04 video opencv






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 at 8:22

























asked Nov 24 at 15:56









TadejP

1067




1067








  • 1




    "It works, but not correctly." - please elaborate. If I read the documentation [1] correctly, waitKey waits for x ms on key press. If no key is pressed it returns -1 and loop in your example breaks... [1] docs.opencv.org/3.1.0/d7/dfc/…
    – honza-kasik
    Nov 24 at 17:03














  • 1




    "It works, but not correctly." - please elaborate. If I read the documentation [1] correctly, waitKey waits for x ms on key press. If no key is pressed it returns -1 and loop in your example breaks... [1] docs.opencv.org/3.1.0/d7/dfc/…
    – honza-kasik
    Nov 24 at 17:03








1




1




"It works, but not correctly." - please elaborate. If I read the documentation [1] correctly, waitKey waits for x ms on key press. If no key is pressed it returns -1 and loop in your example breaks... [1] docs.opencv.org/3.1.0/d7/dfc/…
– honza-kasik
Nov 24 at 17:03




"It works, but not correctly." - please elaborate. If I read the documentation [1] correctly, waitKey waits for x ms on key press. If no key is pressed it returns -1 and loop in your example breaks... [1] docs.opencv.org/3.1.0/d7/dfc/…
– honza-kasik
Nov 24 at 17:03










1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










Obviously API implementation changed from 2.4.9 to 3.2 so example needs to be corrected.



In ver. 2.4.9 when no key pressed in x ms time returns -1



In ver. 3.2 when no key pressed in x ms time returns 255



So code for both versions for me looks like this:



int k; // key
k=waitKey(30);
if( 255!=k && -1!=k )
break;





share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "89"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1095681%2fin-18-04-opencv-waitkey-loop-exit-immediately%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    Obviously API implementation changed from 2.4.9 to 3.2 so example needs to be corrected.



    In ver. 2.4.9 when no key pressed in x ms time returns -1



    In ver. 3.2 when no key pressed in x ms time returns 255



    So code for both versions for me looks like this:



    int k; // key
    k=waitKey(30);
    if( 255!=k && -1!=k )
    break;





    share|improve this answer



























      up vote
      0
      down vote



      accepted










      Obviously API implementation changed from 2.4.9 to 3.2 so example needs to be corrected.



      In ver. 2.4.9 when no key pressed in x ms time returns -1



      In ver. 3.2 when no key pressed in x ms time returns 255



      So code for both versions for me looks like this:



      int k; // key
      k=waitKey(30);
      if( 255!=k && -1!=k )
      break;





      share|improve this answer

























        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        Obviously API implementation changed from 2.4.9 to 3.2 so example needs to be corrected.



        In ver. 2.4.9 when no key pressed in x ms time returns -1



        In ver. 3.2 when no key pressed in x ms time returns 255



        So code for both versions for me looks like this:



        int k; // key
        k=waitKey(30);
        if( 255!=k && -1!=k )
        break;





        share|improve this answer














        Obviously API implementation changed from 2.4.9 to 3.2 so example needs to be corrected.



        In ver. 2.4.9 when no key pressed in x ms time returns -1



        In ver. 3.2 when no key pressed in x ms time returns 255



        So code for both versions for me looks like this:



        int k; // key
        k=waitKey(30);
        if( 255!=k && -1!=k )
        break;






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 25 at 8:25

























        answered Nov 25 at 8:20









        TadejP

        1067




        1067






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1095681%2fin-18-04-opencv-waitkey-loop-exit-immediately%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            數位音樂下載

            When can things happen in Etherscan, such as the picture below?

            格利澤436b