user992520
user992520

Reputation:

opencv circle detection with video

is there a way to wait until something happens(while loop) or wait wait 10 seconds before doing a circle detection, but still displaying the video. i have tried it with while loop but if condition is not met, frames will not be displayed as code does not get the cvShow\iamge().

Upvotes: 1

Views: 863

Answers (2)

karlphillip
karlphillip

Reputation: 93410

Yes, it's possible, but you will have to use threads. Declare a global variable bool exec_circle_detection = false; and start a 2nd thread. On this thread, call sleep(10) to wait for 10 seconds and then change exec_circle_detection to true.

In the main thread, inside the frame grabbing loop, you check if the boolean variable is set to true, and in case it isn't, you won't process the frame. This part would look something like this (in C):

char key = 0;
while (key != 27) // ESC
{    
  frame = cvQueryFrame(capture);
  if (!frame) 
  {
      fprintf( stderr, "!!! cvQueryFrame failed!\n" );
      break;
  }

  if (exec_circle_detection)
  {
      // execute custom processing
  }

  // Display processed frame
  cvShowImage("result", frame);

  // Exit when user press ESC
  key = cvWaitKey(10);
}

If you plan to do the circle detection once every 10 seconds, you will need to change exec_circle_detection to false after you execute the custom processing. On the secondary thread, adjust your code so there is a while loop changing exec_circle_detection to true every 10 seconds.

Upvotes: 1

Eric
Eric

Reputation: 2341

You can simply run the detection every X frames. Add a frame counter in your code, restarting to 0 when detection is perform, increase by one at each grabbed new frame, and perform detection when the counter is equal to 300 considering your video is displayed at 30 fps. You will get your 10 seconds delay between each detections.

Upvotes: 0

Related Questions