0

I am trying to input the image, L shaped image in black:

L shaped image in black

into my Python code and receive back the coordinates of each corner. I get confused with the pixel approach of cv2 and am trying to figure out a way to create two arrays, x and y, of the corners. Examples for this shape could return:

x = [1, 3, 3, 9, 9, 2, 2, 1]
y = [1, 1, 9, 9, 11, 11, 10, 10]
2
  • Welcome to SO! It's not clear, at least for me, what are you trying to accomplish. Do you want to use or not the cv2 approach? Commented Aug 8, 2020 at 17:14
  • @HemersonTacon I am open using the cv2 approach, but I am a little unfamiliar with it and unsure how to turn the complex coordinates of the pixels into simple coordinates as shown in my question. Commented Aug 8, 2020 at 17:25

1 Answer 1

2

I followed this tutorial to achieve a corner detection:

import numpy as np
import cv2

img = cv2.imread('test.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
gray = np.float32(gray)

corners = cv2.goodFeaturesToTrack(gray, 100, 0.01, 10)
corners = np.int0(corners)

for corner in corners:
    x,y = corner.ravel()
    #x and y are your values of the lsit
    cv2.circle(img,(x,y),3,255,-1)
   
cv2.imshow('Corner',img)
cv2.waitKey()

This result looks like this: The Blue dots are the corners. enter image description here

Sign up to request clarification or add additional context in comments.

5 Comments

Welcome to SO! Please take a moment to read this guide and try to improve your answer.
edited the answer. Sorry for bad answer hope this is better!
@SirBaum Thank you so much for the helpful link! I achieved the same result. But I am more looking to make two arrays, one of x and one y, for the corners. I am having trouble converting the corner pixel coords into useful coordinates for my program. For example, I am getting [[[570 781]] [[326 537]] [[977 537]] [[977 374]] [[326 374]] [[733 781]] [[733 130]] [[570 130]] [[568 539]] [[735 539]] [[735 372]] [[568 372]]] ....
Aren't that the pixel values? Your Image has an resolution of 1260x945, that could be the "coordinates" of the corners
@SirBaum You are right, the ravel() function doesnt seem to store the coordinates for me too well, so I am going to try to append through the for loop to get my arrays. Thank you!

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.