Ask Your Question
0

i have problems with handling mouse event in opencv

asked 2013-12-13 11:47:32 -0600

amin.karimi gravatar image

updated 2013-12-13 14:56:28 -0600

i want to write a program with this feature:

1:when a user click left button of mouse on windows a circle is constructed with for ex radius (15)

at first i make a black image 500*500

and i use setMouseCallback for my_mouse_callback and in function my_mouse_callback i write my

circle code ,when run the program there arent any errors but only there is a black image 500*500 that when i click left button of mouse nothing happens, i know my program has trouble but where? please help me my program is like this:

void my_mouse_callback(int event, int x, int y, int flags, void* param);

int main() { int i,j,k;

Mat image;
image.create(500,500,CV_8UC3);

namedWindow("amin");

for(i=0;i<500;i++){
    for(j=0;j<500;j++){
        for(k=0;k<3;k++){
            Vec3b &intensity = image.at<vec3b>(j, i);
            intensity.val[k]=0; 
        }
    } 
} 

setMouseCallback( "amin", my_mouse_callback, &image );

imshow("amin",image);
waitKey(0);

return(0);

}

void my_mouse_callback( int event, int x, int y, int flags, void* param ) {
if(event==CV_EVENT_LBUTTONDOWN){
    circle( image, Point(x,y), 20, Scalar(0xff,0xff,0xff) );
}

}

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-12-13 23:17:36 -0600

Daniil Osokin gravatar image

Hi Amin, you should show modyfied image after draw a circle, so


if(event==CV_EVENT_LBUTTONDOWN){
    circle( image, Point(x,y), 20, Scalar(0xff,0xff,0xff) );
    imshow("amin", image);
}

should help.

edit flag offensive delete link more

Comments

hi daniil yes it is true thanks for your help only 1 questin ? what is voidparam argument in my_mouse_callback ? because i should add Mat image = *((Mat)param); to may function what is this? without this with add your advice again my program doesnt work

amin.karimi gravatar imageamin.karimi ( 2013-12-14 01:05:40 -0600 )edit

Question Tools

Stats

Asked: 2013-12-13 11:47:32 -0600

Seen: 314 times

Last updated: Dec 13 '13