Reputation: 177
I have an image of a person head from which I detected the corner points. Here are my code and result from it:
import cv2
import numpy as np
Head = cv2.imread('Head.jpg')
#Corner detection
gray = cv2.cvtColor(Head, cv2.COLOR_BGR2GRAY)
gray = np.float32(gray)
corners = cv2.goodFeaturesToTrack(gray, 50, 0.01, 10)
corners = np.int0(corners)
for corner in corners:
x,y = corner.ravel()
cv2.circle(Head, (x,y), 3, 255, -1)
z = np.max(y)
cv2.circle(Head, (x,z), 5, (0,0,255), -1)
cv2.imshow('Corner', Head)
cv2.waitKey(0)
cv2.destroyAllWindows()
Head Image:
Corner Detected:
Here, I am trying to point out only two corners in neck area(Lowest ones in above image). For that, I find out the max y from numpy array of corners and plot the point in red point. But, its plotting red point in eye. What I am doing wrong?
How do I find out the coordinate points of neck(lowest 2 corner points only)??
Upvotes: 0
Views: 711
Reputation: 181
The issue is in this line:
z = np.max(y)
Here the value of y will just be the value of the last corner looked at in the previous loop. What you can do is to create a list of all the coordinate of the corners, and then order the list based on the y value:
ordered_coords = [ corner.ravel() for corner in corners ]
ordered_coords.sort(key=lambda x: x[1])
The two corners you're looking for with the highest y value will then be the last two elements in the list.
cv2.circle(Head, ordered_coords[-1], 5, (0,0,255), -1)
Upvotes: 1