Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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;
}