-1

I have created a function, let's call it function1, this function use a while loop to read a video with Opencv my code is very long so I add an example to explain my problem. When I call this function 2 times in the main it's stops when she finish the first call and don't execute the second call I can't figure out why. How to fix the problem and call the function 2 times.

void function1(param1, param2)
{
    char key = 'a';
    while (key != 27)
    {
        cap >> frameFromVideo;
    }
}

int main(int argc, char* argv[]) 
{
    function1(param1, param2);
    function1(param1, param2)
    std::system("pause");
    return 0;
}
user1810087
  • 5,146
  • 1
  • 41
  • 76
all.west
  • 71
  • 1
  • 1
  • 11
  • 2
    Please provide a [mcve](https://stackoverflow.com/help/minimal-reproducible-example). What is `cap`? did you try to debug your program? – user1810087 Jan 28 '20 at 08:54
  • 1
    provide [minimum reproducible code](https://stackoverflow.com/help/minimal-reproducible-example). and refer [What is a debugger and how can it help me diagnose problems?](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems) – TruthSeeker Jan 28 '20 at 08:54
  • 1
    The first call never finishes - your loop is equivalent to `while (true)...` – molbdnilo Jan 28 '20 at 09:15

1 Answers1

1

You never call key=waitKey(5); in the loop. Your key always equals 'a', anl loop never breaks.

Andrey Smorodov
  • 10,649
  • 2
  • 35
  • 42
  • @ user1810087 cap is a video capture that capture frames from a video. @Andrey Smorodov I add 'break' if Frame is empty and it's working – all.west Jan 28 '20 at 16:04