Ask Your Question

Michele's profile - activity

2017-03-09 19:06:34 -0600 received badge  Taxonomist
2013-08-27 16:00:09 -0600 commented answer Using mouse to paint an area of video with OpenCV

Hi! Thank you for helping me, =]. I modified this:

void pinta(IplImage* image, int x, int y){ cvFloodFill (image, cvPoint (x,y), cvScalar(103), cvScalarAll(2), cvScalarAll(2), 0, CV_FLOODFILL_FIXED_RANGE , 0); cvShowImage("saida",image); }

And it worked, =]!

2013-08-27 09:12:14 -0600 asked a question Using mouse to paint an area of video with OpenCV

Hi!

I want to paint an area of my video using mouse when the video is paused, but I'm having a little problem. When I pause the video and try to paint a region, the painted area only appears after I press any key on my keyboard (which is not implemented it). I wonder what I could do to the painted area appears when I press the mouse button?

Thank you, : )

My code:

//mouse callback
void rotina_mouse(int event, int x, int y, int flags, void* param);
bool continua = false;

//function to paint
void pinta(IplImage* image, int x, int y){
     cvFloodFill (image, cvPoint (x,y), cvScalar(103), cvScalarAll(2), cvScalarAll(2), 0, CV_FLOODFILL_FIXED_RANGE , 0);
}

//main program
int _tmain(int argc, _TCHAR* argv[])
{
    cvNamedWindow ("saida", CV_WINDOW_AUTOSIZE);
    CvCapture* g_capture  = cvCreateFileCapture ("vid.avi");
    IplImage* frame = cvQueryFrame(g_capture);
    IplImage* temp = cvCloneImage( frame );
    cvSetMouseCallback("saida",rotina_mouse,(void*) frame);

    while(1){

        frame = cvQueryFrame(g_capture);    
        cvNot(frame, frame);
        cvCopyImage( frame, temp );
        cvShowImage("saida", temp);

        if(!frame) break;

        //pause with 'p'
        char e = cvWaitKey(33);
        if(e==112){

        while(1){
            cvCopyImage( frame, temp );
            cvShowImage("saida", temp);
            char d = cvWaitKey(0);
            if(d==112) break;
        }
        }

        //close video with'esc'
        if(e==27) break;
    }

    cvReleaseCapture (&g_capture);
    cvDestroyWindow("saida");

    return 0;   
}

//mouse callback
void rotina_mouse(int event, int x, int y, int flags, void* param) {
    IplImage* image = (IplImage*) param;
        switch( event ) {
            case CV_EVENT_MOUSEMOVE: {
                    if(continua==true)
                    pinta(image, x, y);         
            }
            break;
            case CV_EVENT_LBUTTONDOWN: {
                pinta(image, x, y);
                continua=true;
            }
            break;
            case CV_EVENT_LBUTTONUP: {
                continua=false;
            }
            break;
            default:
            break;
        }
}