changed a funtion
This commit is contained in:
parent
d9d0cd4517
commit
a2108cc7c9
82
landmarks.py
82
landmarks.py
@ -280,6 +280,7 @@ class Landmarker:
|
|||||||
distance = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
|
distance = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
|
||||||
return distance
|
return distance
|
||||||
|
|
||||||
|
|
||||||
def get_center_top_point(self, side_results):
|
def get_center_top_point(self, side_results):
|
||||||
gray_image = cv2.cvtColor(
|
gray_image = cv2.cvtColor(
|
||||||
self.side_image_keypoints,
|
self.side_image_keypoints,
|
||||||
@ -290,42 +291,65 @@ class Landmarker:
|
|||||||
0 : int(self.side_image_resized.shape[0] / 2),
|
0 : int(self.side_image_resized.shape[0] / 2),
|
||||||
:,
|
:,
|
||||||
]
|
]
|
||||||
self.edges = cv2.Canny(roi, 50, 150)
|
edges = cv2.Canny(roi, 50, 150)
|
||||||
contours, _ = cv2.findContours(
|
contours, _ = cv2.findContours(
|
||||||
self.edges.copy(),
|
edges,
|
||||||
cv2.RETR_TREE,
|
cv2.RETR_EXTERNAL,
|
||||||
cv2.CHAIN_APPROX_SIMPLE,
|
cv2.CHAIN_APPROX_SIMPLE,
|
||||||
)
|
)
|
||||||
max_contour = max(contours, key=cv2.contourArea)
|
xt, yt = None, None
|
||||||
rect = cv2.minAreaRect(max_contour)
|
topmost_point = None
|
||||||
box = cv2.boxPoints(rect)
|
|
||||||
box = sorted(
|
|
||||||
list(box),
|
|
||||||
key=lambda p: p[1],
|
|
||||||
)
|
|
||||||
top_point = min(
|
|
||||||
box[0],
|
|
||||||
box[1],
|
|
||||||
key=lambda p: p[0],
|
|
||||||
)
|
|
||||||
|
|
||||||
left_hip = side_results.pose_landmarks.landmark[LANDMARK_NAME_TO_INDEX["left_hip"]]
|
if contours:
|
||||||
right_hip = side_results.pose_landmarks.landmark[LANDMARK_NAME_TO_INDEX["right_hip"]]
|
largest_contour = max(
|
||||||
|
contours,
|
||||||
|
key=cv2.contourArea,
|
||||||
|
)
|
||||||
|
topmost_point = tuple(largest_contour[largest_contour[:, :, 1].argmin()][0])
|
||||||
|
xt, yt = topmost_point
|
||||||
|
|
||||||
center_x = (left_hip.x + right_hip.x) / 2
|
cv2.circle(
|
||||||
center_y = (left_hip.y + right_hip.y) / 2
|
self.side_image_keypoints,
|
||||||
|
(xt, yt),
|
||||||
|
2,
|
||||||
|
(255, 255, 0),
|
||||||
|
-1,
|
||||||
|
)
|
||||||
|
|
||||||
center_x, center_y = (
|
xc, yc = None, None
|
||||||
int(center_x * self.resized_width),
|
landmarks = side_results.pose_landmarks.landmark
|
||||||
int(center_y * self.resized_height),
|
|
||||||
)
|
|
||||||
|
|
||||||
self.pixel_distance = self.euclidean_distance(
|
if side_results.pose_landmarks:
|
||||||
top_point[0],
|
left_hip = landmarks[LANDMARK_NAME_TO_INDEX["left_hip"]]
|
||||||
top_point[1],
|
right_hip = landmarks[LANDMARK_NAME_TO_INDEX["right_hip"]]
|
||||||
center_x,
|
center_point = (
|
||||||
center_y,
|
(left_hip.x + right_hip.x) / 2,
|
||||||
)
|
(left_hip.y + right_hip.y) / 2,
|
||||||
|
)
|
||||||
|
center_point = (
|
||||||
|
int(center_point[0] * self.side_image_resized.shape[1]),
|
||||||
|
int(center_point[1] * self.side_image_resized.shape[0]),
|
||||||
|
)
|
||||||
|
xc, yc = center_point
|
||||||
|
self.circle(
|
||||||
|
self.side_image_keypoints,
|
||||||
|
xc,
|
||||||
|
yc,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.pixel_distance = self.euclidean_distance(xc, yc, xt, yt)
|
||||||
|
logging.debug(
|
||||||
|
"top_center_pixel_distance: %s",
|
||||||
|
self.pixel_distance,
|
||||||
|
)
|
||||||
|
self.pixel_height = self.pixel_distance * 2
|
||||||
|
logging.debug(
|
||||||
|
"pixel height: %s ",
|
||||||
|
self.pixel_height,
|
||||||
|
)
|
||||||
|
self.distance = self.euclidean_distance(xc, yc, xt, yt) * self.pixel_to_metric_ratio()
|
||||||
|
|
||||||
|
return self.distance
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
landmarker = Landmarker()
|
landmarker = Landmarker()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user