Ask Your Question

Wait for a mouse click?

asked 2013-06-14 19:51:53 -0500

yes123 gravatar image

updated 2018-10-13 10:16:48 -0500

I have a video. I would like to show the next frame only if the user clicks on a pixel on the current frame.

(The user must select a point in each frame)

Without using waitKey(0) I could I make opencv waiting for the mouse click before showing the next frame?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-06-15 06:46:36 -0500

berak gravatar image

you can't do without waitkey, if you plan to use imshow.

but you could make the grab/read part of the capture depend on mouseclick:

// avoid global vars, pass a struct* instead:
struct User
    VideoCapture cap;
    Mat m;

void mouse(int k, int x, int y, int s, void *p)
    User * u  = (User*)p;
    if ( k && s )
int main(int,char**)
    User u;
    while( u.cap.isOpened() )
        if (! u.m.empty())
        int k = waitKey(10);
        if ( k==27 ) break;
    return 0;
edit flag offensive delete link more

Question Tools


Asked: 2013-06-14 19:51:53 -0500

Seen: 7,102 times

Last updated: Jun 15 '13