I am using OpenCV in python on OSX (10.10.5). I'm just starting out, so maybe I made a stupid mistake. However, I did not find anything that could solve this problem.
I have a mouse callback function that makes a list containing the coordinates of each point that the downloaded image is clicked on.
Now I would like to use flags in the mouse callback function to control whether I add coordinates to the list or add "NA, NA" (for example, if there is no dot in the image, I could hold the shift key and click on the image, and placeholder will be added instead of coordinates).
Although the "event" portion of the mouse callback part works *, the flags information does not seem to be available.
Here's the mouse callback function:
img_points = [] def write_points(event, x, y, flags, param): global img_points if event == cv2.EVENT_LBUTTONDOWN and flags != cv2.EVENT_FLAG_SHIFTKEY: img_points.append((x,y)) print img_points elif event == cv2.EVENT_LBUTTONDOWN and flags == cv2.EVENT_FLAG_SHIFTKEY: img_points.append(('NA','NA')) print img_points
I tried different versions of this, and as far as I can tell, the problem is that the function event_flag_shiftkey (or any other event_flag information) is not available to the function.
Here's what happens if I change the code differently:
-If I do not add anything about the flag, the coordinates of each point clicked on are added to img_points, so part of the event looks normal.
-If I use the function written above, the coordinates of each point that is pressed will be added (regardless of whether the shift key is pressed). Therefore, the flags! = Cv2.EVENT_FLAG_SHIFTKEY must always be true.
-If I use the code as described above, but replace the flags! = Cv2.EVENT_FLAG_SHIFTKEY, say flags == cv2.EVENT_FLAG_CTRLKEY, then nothing happens when I press regardless of whether I hold any buttons. This suggests that no matter what I do with the keyboard, the flags == cv2.EVENT_FLAG_CTRLKEY and flags == cv2.EVENT_FLAG_SHIFTKEY are both always false.
Any ideas what is wrong here? Am I using event flags incorrectly? Is this a problem with how OSX encodes keys / right clicks? How can i fix this?
* Note: in fact, the EVENT_LBUTTONDOWN event is the only event that works. Like this post , EVENT_RBUTTONDOWN and double-click events do not work. (A double click is registered as two clicks and adds two sets of coordinates). I tried this with both the trackpad and the external mouse. (Responding to another post did not resolve the issue).