Ask Your Question

Revision history [back]

Mouse click x and y coordinates are consistently incorrect on Linux

System information (version)
  • OpenCV => :3.4.3.18
  • Operating System / Platform => Linux (Raspberry Pi 3 Model B)
  • Compiler => Thonny Python IDE

Hello,

I wrote a simple image display script in Python ( imageDisplay.txt) that cycles through 3 jpg images stored in the same folder. When I click on the right side of the picture, the next picture in the cycle should be displayed. When I click on the left side of the picture the previous image in the cycle should be displayed. The x coordinates on my screen range from 0 to ~1300 so I set a left-side click to be x<600 and a right-side click to be x>600.

My script works perfectly on a Windows 64 bit computer, however it doesn't work when I run it on my Raspberry Pi Model 3. I'm not sure if it's a Linux problem or if there's some sort of incompatibility with the Pi. When I click the right side of the image once, x correctly displayed as a value greater than 600. However, when I click the exact same spot again a second time, a value less than 600 is display. As I continue clicking the exact same spot, the x coordinate alternates between correct/incorrect x values .

In the screenshot below, I clicked the exact same spot on the right side of my image each time and printed out the associated x coordinate. As you can see, the x coordinate alternates between x>600 and x<600. image description

I have a similar problem with the y coordinates. Am I missing something? Any help is greatly appreciated, this really has me stumped. Thank you!

Mouse click x and y coordinates are consistently incorrect on Linux

System information (version)
  • OpenCV => :3.4.3.18
  • Operating System / Platform => Linux (Raspberry Pi 3 Model B)
  • Compiler => Thonny Python IDE

Hello,

I wrote a simple image display script in Python ( imageDisplay.txt) that cycles through 3 jpg images stored in the same folder. When I click on the right side of the picture, the next picture in the cycle should be displayed. When I click on the left side of the picture the previous image in the cycle should be displayed. The x coordinates on my screen range from 0 to ~1300 so I set a left-side click to be x<600 and a right-side click to be x>600.

My script works perfectly on a Windows 64 bit computer, however it doesn't work when I run it on my Raspberry Pi Model 3. I'm not sure if it's a Linux problem or if there's some sort of incompatibility with the Pi. When I click the right side of the image once, x correctly displayed as a value greater than 600. However, when I click the exact same spot again a second time, a value less than 600 is display. As I continue clicking the exact same spot, the x coordinate alternates between correct/incorrect x values .

In the screenshot below, here, I clicked the exact same spot on the right side of my image each time and printed out the associated x coordinate. As you can see, the x coordinate alternates between x>600 and x<600. image description

I have a similar problem with the y coordinates. Am I missing something? Any help is greatly appreciated, this really has me stumped. Thank you!

Mouse click x and y coordinates are consistently incorrect on Linux

System information (version)
  • OpenCV => :3.4.3.18
  • Operating System / Platform => Linux (Raspberry Pi 3 Model B)
  • Compiler => Thonny Python IDE

Hello,

I wrote a simple image display script in Python ( imageDisplay.txt) that cycles through 3 jpg images stored in the same folder. When I click on the right side of the picture, the next picture in the cycle should be displayed. When I click on the left side of the picture the previous image in the cycle should be displayed. The x coordinates on my screen range from 0 to ~1300 so I set a left-side click to be x<600 and a right-side click to be x>600.

My script works perfectly on a Windows 64 bit computer, however it doesn't work when I run it on my Raspberry Pi Model 3. I'm not sure if it's a Linux problem or if there's some sort of incompatibility with the Pi. When I click the right side of the image once, x correctly displayed as a value greater than 600. However, when I click the exact same spot again a second time, a value less than 600 is display. As I continue clicking the exact same spot, the x coordinate alternates between correct/incorrect x values .

In the screenshot here, I clicked the exact same spot on the right side of my image each time and printed out the associated x coordinate. As you can see, the x coordinate alternates between x>600 and x<600.

I have a similar problem with the y coordinates. Am I missing something? Any help is greatly appreciated, this really has me stumped. Thank you!

import cv2 #image processing
import glob #finds files in pathnames with certain parameters (ie jpg pictures)

#returns a list of all jpg images in filepath
images = [cv2.imread(file) for file in glob.glob("/home/pi/Pictures/*.jpg")]
i=0 #list index

def cycleForward():#cycle forward in the list
    global i, images
    if i==len(images)-1:
        i=0
    else:
        i+=1

def cycleBackward():#cycle backwards in the list
    global i, images
    if i==0:
        i=len(images)-1
    else:
        i-=1

def cycleImage(event,x,y,flag,param):#left mouse click to cycle through images
    global i, images 
    if event == cv2.EVENT_LBUTTONDOWN:
        if (x>600):#click the right side of the image to go to the next picture
            cycleForward() 
            print ("Forward "+str(x))  
        if (x<600):#click the left side of the image to go to the previous picture
            cycleBackward()
            print ("Backwards "+str(x))

#create fullscreen image
cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty("window",cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)

cv2.setMouseCallback("window", cycleImage)#monitor for left mouse click

while True:#continuously run
    img = images[i]
    cv2.imshow("window", img)#display one image
    key = cv2.waitKey(1) & 0xFF
    if key == 27:#press escape to stop image display
        cv2.destroyAllWindows() #destroys all created windows
        break

Mouse click x and y coordinates are consistently incorrect on Linux

System information (version)
  • OpenCV => :3.4.3.18
  • Operating System / Platform => Linux (Raspberry Pi 3 Model B)
  • Compiler => Thonny Python IDE

Hello,

I wrote a simple image display script in Python that cycles through 3 jpg images stored in the same folder. When I click on the right side of the picture, the next picture in the cycle should be displayed. When I click on the left side of the picture the previous image in the cycle should be displayed. The x coordinates on my screen range from 0 to ~1300 so I set a left-side click to be x<600 and a right-side click to be x>600.

My script works perfectly on a Windows 64 bit computer, however it doesn't work when I run it on my Raspberry Pi Model 3. I'm not sure if it's a Linux problem or if there's some sort of incompatibility with the Pi. When I click the right side of the image once, x correctly displayed as a value greater than 600. However, when I click the exact same spot again a second time, a value less than 600 is display. As I continue clicking the exact same spot, the x coordinate alternates between correct/incorrect x values .

In the screenshot here, I clicked the exact same spot on the right side of my image each time and printed out the associated x coordinate. As you can see, the x coordinate alternates between x>600 and x<600.

I have a similar problem with the y coordinates. Am I missing something? Any help is greatly appreciated, this really has me stumped. Thank you!

import cv2 #image processing
import glob #finds files in pathnames with certain parameters (ie jpg pictures)

#returns a list of all jpg images in filepath
images = [cv2.imread(file) for file in glob.glob("/home/pi/Pictures/*.jpg")]
i=0 #list index

def cycleForward():#cycle forward in the list
    global i, images
    if i==len(images)-1:
        i=0
    else:
        i+=1

def cycleBackward():#cycle backwards in the list
    global i, images
    if i==0:
        i=len(images)-1
    else:
        i-=1

def cycleImage(event,x,y,flag,param):#left mouse click to cycle through images
    global i, images 
    if event == cv2.EVENT_LBUTTONDOWN:
        if (x>600):#click the right side of the image to go to the next picture
            cycleForward() 
            print ("Forward "+str(x))  
        if (x<600):#click the left side of the image to go to the previous picture
            cycleBackward()
            print ("Backwards "+str(x))

#create fullscreen image
cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty("window",cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)

cv2.setMouseCallback("window", cycleImage)#monitor for left mouse click

while True:#continuously run
    img = images[i]
    cv2.imshow("window", img)#display one image
    key = cv2.waitKey(1) & 0xFF
    if key == 27:#press escape to stop image display
        cv2.destroyAllWindows() #destroys all created windows
        break
cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty("window",cv2.WND_PROP_FULLSCREEN//2,cv2.WINDOW_FULLSCREEN//2)

Mouse click x and y coordinates are consistently incorrect on Linux

System information (version)
  • OpenCV => :3.4.3.18
  • Operating System / Platform => Linux (Raspberry Pi 3 Model B)
  • Compiler => Thonny Python IDE

Hello,

I wrote a simple image display script in Python that cycles through 3 jpg images stored in the same folder. When I click on the right side of the picture, the next picture in the cycle should be displayed. When I click on the left side of the picture the previous image in the cycle should be displayed. The x coordinates on my screen range from 0 to ~1300 so I set a left-side click to be x<600 and a right-side click to be x>600.

My script works perfectly on a Windows 64 bit computer, however it doesn't work when I run it on my Raspberry Pi Model 3. I'm not sure if it's a Linux problem or if there's some sort of incompatibility with the Pi. When I click the right side of the image once, x correctly displayed as a value greater than 600. However, when I click the exact same spot again a second time, a value less than 600 is display. As I continue clicking the exact same spot, the x coordinate alternates between correct/incorrect x values .

In the screenshot here, I clicked the exact same spot on the right side of my image each time and printed out the associated x coordinate. As you can see, the x coordinate alternates between x>600 and x<600.

I have a similar problem with the y coordinates. Am I missing something? Any help is greatly appreciated, this really has me stumped. Thank you!

import cv2 #image processing
import glob #finds files in pathnames with certain parameters (ie jpg pictures)

#returns a list of all jpg images in filepath
images = [cv2.imread(file) for file in glob.glob("/home/pi/Pictures/*.jpg")]
i=0 #list index

def cycleForward():#cycle forward in the list
    global i, images
    if i==len(images)-1:
        i=0
    else:
        i+=1

def cycleBackward():#cycle backwards in the list
    global i, images
    if i==0:
        i=len(images)-1
    else:
        i-=1

def cycleImage(event,x,y,flag,param):#left mouse click to cycle through images
    global i, images 
    if event == cv2.EVENT_LBUTTONDOWN:
        if (x>600):#click the right side of the image to go to the next picture
            cycleForward() 
            print ("Forward "+str(x))  
        if (x<600):#click the left side of the image to go to the previous picture
            cycleBackward()
            print ("Backwards "+str(x))

#create fullscreen image
cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty("window",cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)

cv2.setMouseCallback("window", cycleImage)#monitor for left mouse click

while True:#continuously run
    img = images[i]
    cv2.imshow("window", img)#display one image
    key = cv2.waitKey(1) & 0xFF
    if key == 27:#press escape to stop image display
        cv2.destroyAllWindows() #destroys all created windows
        break
cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty("window",cv2.WND_PROP_FULLSCREEN//2,cv2.WINDOW_FULLSCREEN//2)

Mouse click x and y coordinates are consistently incorrect on LinuxLinux[SOLVED]

System information (version)
  • OpenCV => :3.4.3.18
  • Operating System / Platform => Linux (Raspberry Pi 3 Model B)
  • Compiler => Thonny Python IDE

Hello,

I wrote a simple image display script in Python that cycles through 3 jpg images stored in the same folder. When I click on the right side of the picture, the next picture in the cycle should be displayed. When I click on the left side of the picture the previous image in the cycle should be displayed. The x coordinates on my screen range from 0 to ~1300 so I set a left-side click to be x<600 and a right-side click to be x>600.

My script works perfectly on a Windows 64 bit computer, however it doesn't work when I run it on my Raspberry Pi Model 3. I'm not sure if it's a Linux problem or if there's some sort of incompatibility with the Pi. When I click the right side of the image once, x correctly displayed as a value greater than 600. However, when I click the exact same spot again a second time, a value less than 600 is display. As I continue clicking the exact same spot, the x coordinate alternates between correct/incorrect x values .

In the screenshot here, I clicked the exact same spot on the right side of my image each time and printed out the associated x coordinate. As you can see, the x coordinate alternates between x>600 and x<600.

I have a similar problem with the y coordinates. Am I missing something? Any help is greatly appreciated, this really has me stumped. Thank you!

import cv2 #image processing
import glob #finds files in pathnames with certain parameters (ie jpg pictures)

#returns a list of all jpg images in filepath
images = [cv2.imread(file) for file in glob.glob("/home/pi/Pictures/*.jpg")]
i=0 #list index

def cycleForward():#cycle forward in the list
    global i, images
    if i==len(images)-1:
        i=0
    else:
        i+=1

def cycleBackward():#cycle backwards in the list
    global i, images
    if i==0:
        i=len(images)-1
    else:
        i-=1

def cycleImage(event,x,y,flag,param):#left mouse click to cycle through images
    global i, images 
    if event == cv2.EVENT_LBUTTONDOWN:
        if (x>600):#click the right side of the image to go to the next picture
            cycleForward() 
            print ("Forward "+str(x))  
        if (x<600):#click the left side of the image to go to the previous picture
            cycleBackward()
            print ("Backwards "+str(x))

#create fullscreen image
cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty("window",cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)

cv2.setMouseCallback("window", cycleImage)#monitor for left mouse click

while True:#continuously run
    img = images[i]
    cv2.imshow("window", img)#display one image
    key = cv2.waitKey(1) & 0xFF
    if key == 27:#press escape to stop image display
        cv2.destroyAllWindows() #destroys all created windows
        break
cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty("window",cv2.WND_PROP_FULLSCREEN//2,cv2.WINDOW_FULLSCREEN//2)