Ask Your Question

Revision history [back]

Mat img;

void CallBackFunc(int event, int x, int y, int flags, void* userdata){

if(event == EVENT_LBUTTONDOWN){

    Mat dst;

    dst = img.clone();

    int data=50;
    Rect dikdortgen( (x-data/2), (y-data/2), data, data );
    rectangle(dst, dikdortgen, CV_RGB(255,255,255),2);

    imshow("My Window", dst);
 }
}


int main(int argc, char** argv){

 int kontrol=0;
 img = imread("Nature.JPG"); // Read image from file 

 if ( img.empty() )  //if fail to read the image
 { 
      cout << "Error loading the image" << endl;
      return -1; 
 }

 namedWindow("My Window", CV_WINDOW_NORMAL); //Create a window

 setMouseCallback("My Window", CallBackFunc, 0); //set the callback function 

 if(kontrol==0){
    imshow("My Window", img); //show the image
    kontrol=1;
 }

 waitKey(0); // Wait until user press some key   
 return 0;
}