changed a funtion

This commit is contained in:
aparnah 2024-07-16 16:06:17 +05:30
parent d9d0cd4517
commit a2108cc7c9

View File

@ -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( if contours:
list(box), largest_contour = max(
key=lambda p: p[1], contours,
) key=cv2.contourArea,
top_point = min( )
box[0], topmost_point = tuple(largest_contour[largest_contour[:, :, 1].argmin()][0])
box[1], xt, yt = topmost_point
key=lambda p: p[0],
) cv2.circle(
self.side_image_keypoints,
left_hip = side_results.pose_landmarks.landmark[LANDMARK_NAME_TO_INDEX["left_hip"]] (xt, yt),
right_hip = side_results.pose_landmarks.landmark[LANDMARK_NAME_TO_INDEX["right_hip"]] 2,
(255, 255, 0),
center_x = (left_hip.x + right_hip.x) / 2 -1,
center_y = (left_hip.y + right_hip.y) / 2 )
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),
) if side_results.pose_landmarks:
left_hip = landmarks[LANDMARK_NAME_TO_INDEX["left_hip"]]
self.pixel_distance = self.euclidean_distance( right_hip = landmarks[LANDMARK_NAME_TO_INDEX["right_hip"]]
top_point[0], center_point = (
top_point[1], (left_hip.x + right_hip.x) / 2,
center_x, (left_hip.y + right_hip.y) / 2,
center_y, )
) 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()