Python Forum

Full Version: cv2/numpy
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to obtain x,y coordinates by clicking on a graph in png format.
The following code works properly but it looks like that
x and y have a strange range, for instance y decreases its value the further you go up.
What exactly should I implement in the following code in order to pre-establish
the x and y range?
I have tried with numpy, but it does not work.

import cv2
import numpy as np

def click_event(event, x, y, flags, param):
    #x=np.linspace(0,10,1) when enabled they
    #y=np.linspace(0,5,1)  just print [0.] [0.] for every mouse click
    if event == cv2.EVENT_LBUTTONDOWN:
        print (x, y)

file_name= (r"\Users\Desktop\pic.png")

img = cv2.imread(file_name)
print(img.shape)
cv2.imshow('original', img)
cv2.setMouseCallback("original", click_event)
cv2.waitKey(0)
cv2.destroyAllWindows
just so i understand, in the click_event function definition - inside the parentheses - event actually replaces the more conventional self ?
I am not sure what you mean with 'self' unless classes are involved.
I can only tell you that from what I am understanding, I would need an array to establish the x and y range, but I am not sure how to implement it. I would also need to 'treat' the image as an actual graph, which means that the general x,y coordinate values should be followed as usual. For instance, the further to the right you move, the more x should increase, and the further up, the larger y should be.
As right now, if I go further up, y decreases.
hehe, i was just asking, i'm just starting out myself with python, i don't have the knowledge yet to answer your question, don't worry someone else will for sure
hope so :)