Perseus784
Perseus784

Reputation: 104

Find corners of a triangle

I'm trying to find the pixel values of the corners of these triangles. I can mark the points on the output image but don't know how to obtain it as variable for printing. I want these corner values to be stored in a variable. This is the input image "triangles.png". This is the output image.

import cv2
import numpy as np
from matplotlib import pyplot as plt
filename = 'triangles.png'
img = cv2.imread(filename)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
gray = np.float32(gray)
dst = cv2.cornerHarris(gray,2,3,0.04)
##result is dilated for marking the corners, not important
dst = cv2.dilate(dst,None)
img[dst>0.01*dst.max()]=[250,0,0]
cv2.imshow('dst',img)
if cv2.waitKey(0) & 0xff == 27:
    cv2.destroyAllWindows()

Upvotes: 1

Views: 943

Answers (1)

ingvar
ingvar

Reputation: 4375

dst = cv2.cornerHarris(gray, 2, 3, 0.04)
x, y = np.nonzero(dst > 0.01 * dst.max())

x, y - numpy arrays with x and y coordinates of corners. you can use it later:

coordinates = zip(x, y)

Upvotes: 2

Related Questions