Ask Your Question
1

Wait for a mouse click?

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

yes123 gravatar image

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

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
3

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

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 )
        u->cap.read(u->m);
}
int main(int,char**)
{
    User u;
    namedWindow("i",0);
    setMouseCallback("i",mouse,&u);
    u.cap.open("mona.flv");
    while( u.cap.isOpened() )
    {
        if (! u.m.empty())
            imshow("i",u.m);
        int k = waitKey(10);
        if ( k==27 ) break;
    }
    return 0;
}
edit flag offensive delete link more

Question Tools

Stats

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

Seen: 9,772 times

Last updated: Jun 15 '13