Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
cv2/numpy
#1
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
Reply
#2
just so i understand, in the click_event function definition - inside the parentheses - event actually replaces the more conventional self ?
Reply
#3
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.
Reply
#4
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
Reply
#5
hope so :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Numpy] How to store different data type in one numpy array? water 7 537 Mar-26-2024, 02:18 PM
Last Post: snippsat
  Numpy returns "TypeError: unsupported operand type(s) for *: 'numpy.ufunc' and 'int'" kalle 2 2,599 Jul-19-2022, 06:31 AM
Last Post: paul18fr
  "erlarge" a numpy-matrix to numpy-array PhysChem 2 2,976 Apr-09-2019, 04:54 PM
Last Post: PhysChem

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020