changed a funtion

This commit is contained in:
aparnah 2024-07-16 16:00:50 +05:30
parent 4cdc6e0380
commit 5856721002

View File

@ -189,7 +189,6 @@ class Landmarker:
tablefmt="plain", tablefmt="plain",
) )
print(output) print(output)
self.pose.close() self.pose.close()
def process_images(self): def process_images(self):
@ -290,42 +289,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( topmost_point = tuple(largest_contour[largest_contour[:, :, 1].argmin()][0])
box[0], xt, yt = topmost_point
box[1],
key=lambda p: p[0], cv2.circle(
self.side_image_keypoints,
(xt, yt),
2,
(255, 255, 0),
-1,
) )
left_hip = side_results.pose_landmarks.landmark[LANDMARK_NAME_TO_INDEX["left_hip"]] xc, yc = None, None
right_hip = side_results.pose_landmarks.landmark[LANDMARK_NAME_TO_INDEX["right_hip"]] landmarks = side_results.pose_landmarks.landmark
center_x = (left_hip.x + right_hip.x) / 2 if side_results.pose_landmarks:
center_y = (left_hip.y + right_hip.y) / 2 left_hip = landmarks[LANDMARK_NAME_TO_INDEX["left_hip"]]
right_hip = landmarks[LANDMARK_NAME_TO_INDEX["right_hip"]]
center_x, center_y = ( center_point = (
int(center_x * self.resized_width), (left_hip.x + right_hip.x) / 2,
int(center_y * self.resized_height), (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( self.pixel_distance = self.euclidean_distance(xc, yc, xt, yt)
top_point[0], logging.debug(
top_point[1], "top_center_pixel_distance: %s",
center_x, self.pixel_distance,
center_y,
) )
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()