Mouse callback: Selecting pixel with mouse (Bug #3409)


Added by Josep Bosch over 11 years ago. Updated over 11 years ago.


Status:Done Start date:2013-11-29
Priority:Normal Due date:
Assignee:Josep Bosch % Done:

100%

Category:highgui-gui
Target version:2.4.8
Affected version:2.4.7 (latest release) Operating System:Linux
Difficulty: HW Platform:x64
Pull request:https://github.com/Itseez/opencv/pull/1927

Description

I'm using the [cv2.setMouseCallback][1] function to select a pixel of an image shown in a window.
The callback function returns an x and y integers that represent the position of the pixel in the image, but paying attention to it's behaviour it seems to me that doesn't return the pixel you are over but the rounded value of a point in an imaginary axis.

If you look at the two first images, in both the mouse is over the pixel 0,0 but the result is diferent if you move closer to other pixels.

Ok. I know in a real image the error is insignificant, but is this a bug?

cv2.namedWindow('image',cv2.WINDOW_NORMAL) # Can be resized
cv2.resizeWindow('image', self.w, self.h) #Reasonable size window
cv2.setMouseCallback('image',self.mouse_callback) #Mouse callback
while(not self.finished):
cv2.imshow('image',self.img)
k = cv2.waitKey(4) & 0xFF
if k 27:
breakim
cv2.destroyAllWindows()
# mouse callback function
def mouse_callback(self,event,x,y,flags,param):
if event cv2.EVENT_LBUTTONDOWN:
print x, y
[1]: http://docs.opencv.org/modules/highgui/doc/user_interface.html?highlight=mouse#cv.SetMouseCallback

Associated revisions

Revision ba9bc2d7
Added by Vadim Pisarevsky over 10 years ago

Merge pull request #3409 from fish2000:patch-1

History

Updated by Daniil Osokin over 11 years ago

Hi, Josep! Thank you for attention. Could you please submit fix for this (http://code.opencv.org/projects/opencv/wiki/How_to_contribute)? It will really help!

  • Assignee set to Josep Bosch
  • Category set to highgui-gui
  • Target version set to 2.4.8

Updated by Josep Bosch over 11 years ago

I've done a pull request.

It works fine now:

  • % Done changed from 0 to 50
  • Status changed from New to Open

Updated by Alexander Smorkalov over 11 years ago

  • Pull request set to https://github.com/Itseez/opencv/pull/1927

Updated by Josep Bosch over 11 years ago

  • Status changed from Open to Done
  • % Done changed from 50 to 100

Also available in: Atom PDF