Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

you can just pass your image to the callback-function, and draw your circle there:

void onmouse(int event, int x, int y, int flags, void* param)
{
    if(event==CV_EVENT_LBUTTONDOWN)
    {
        Mat &img = *((Mat*)(param)); // 1st cast it back, then deref
        circle(img,Point(x,y),50,Scalar(0,255,0),1);
    }
}

int main()
{
    Mat img;
    namedWindow("My window", 1); 
    setMouseCallback("My window", onmouse, &img); // pass address of img here
    // ...
}

(some sidenotes:)

  • please don't use polish var-names, or comments, as people in the rest of the world can't read it.
  • please don't mix the c++ api with older c-functions ( cvSetMousCallback, etc )