2

I am working on a photo measurement project in Visual Studio 2010 (C++) with openCV 2.4. What I need to do is to be able to click ANYWHERE on the photo and save the x and y coordinates of my mouse event. Seems simple. However, let's say, for example, my photo is 1920 x 1080. If I try to click the bottom right corner of the image (even zoomed in with a magnifier clicking) I can only click the edge point (1916,1078). If I expand the image it seems to be able to click farther out which makes me think something isn't right. Here are the main parts of my code.

Part that creates the window and sets the callback function

// create a window
cvNamedWindow( "mainWin", CV_WINDOW_NORMAL ); 

// set mouse callback
cvSetMouseCallback("mainWin", onMouse);

// show the image
cvShowImage("mainWin", img );

// wait for a key
cvWaitKey(0);

// release the image
cvReleaseImage(&img );

onMouse event

void onMouse(int event, int x, int y, int flags, void *param){

switch(event){

    case CV_EVENT_LBUTTONDOWN: //single click
        char Char_Array[20];
        sprintf(Char_Array,"Click: %d, %d", x,y);  
        MessageBoxA(NULL, Char_Array, "ERROR", MB_TASKMODAL | MB_OK);

}

Seems like it should be pretty straight forward. Any ideas as to why I can't access the 1920th column or the 1080th row?

Quentin Geissmann
  • 2,240
  • 1
  • 21
  • 36
AMB0027
  • 121
  • 12
  • 1
    The reason you can't click at (1920,1080) is that coordinates are 0-based, the last pixel is (1919, 1079). This doesn't explain why you can't get a result past 1916, however. – Ben Voigt Sep 12 '12 at 16:00
  • 2
    With your code exactly I can go up to (1918, 1078). I have no clue where 1919 and 1079 are, though. Also, you might want to activate moving the mouse with the numpad so that you can actually move pixel by pixel and check it that way. – Sassa Sep 12 '12 at 16:29

0 Answers0