1

I've created random points and added a list these points double. Then I've drawn graphic and save as a image.

I'm able to draw a line from one point to another point with this code :

cv2.line(img=result,pt1=,pt2=,color=(0,255,255),thickness=5)

I'have a problem there . If I use plt.show() for graphic, I have all points coordinates in list. But when I save this graphic as a image and show with cv2 lib, then all points coordinates changes.

  • How can I find these points coordinates on image ?

Graphic

  • For exapmle: On this graphic you can see (1,4) point. If I save this graphic as a image then this point gets a (104, 305) coordinates on image.
import numpy as np
import random
import matplotlib.pyplot as plt
import cv2

points = np.random.randint(0, 9, size=(18,2))
print(points)
plt.plot(points[:,0], points[:,1], '.',color='k')

plt.savefig("graphic.png",bbox_inches="tight")
result = cv2.imread("graphic.png")

cv2.imshow("Graphic",result)
1
  • You have exported the visualization of the points. The space between points in the image is several pixel. For the representation of your data to be accurate as you want it, the resulting image would have to be 9x9 pixels with single dots representing individual points. Don't really know what is the use of it.
    – Croolman
    Commented Jun 16, 2020 at 10:14

1 Answer 1

0

I think you are confusing yourself.

  • Your x,y coordinates start at bottom-left corner of image, have x coordinate first and assume the image is 9 pixels wide.

  • OpenCV stores points relative to the top-left corner, have the y coordinate first and refer to an image hundreds of pixels wide.

1
  • I'm tryin to draw a graphic with 20 random points and save as image this graphic . Then i calculate all outside points and draw a polygon like convex hull method .It's going to be from one point the another point draw a line and the others. I know it's really unnecessary but i have to do with this way cuz about thesis.
    – Atakan ADA
    Commented Jun 16, 2020 at 11:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.