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",
)
print(output)
self.pose.close()
def process_images(self):
@ -290,42 +289,65 @@ class Landmarker:
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(
self.edges.copy(),
cv2.RETR_TREE,
edges,
cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE,
)
max_contour = max(contours, key=cv2.contourArea)
rect = cv2.minAreaRect(max_contour)
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],
)
xt, yt = None, None
topmost_point = None
left_hip = side_results.pose_landmarks.landmark[LANDMARK_NAME_TO_INDEX["left_hip"]]
right_hip = side_results.pose_landmarks.landmark[LANDMARK_NAME_TO_INDEX["right_hip"]]
if contours:
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
center_y = (left_hip.y + right_hip.y) / 2
cv2.circle(
self.side_image_keypoints,
(xt, yt),
2,
(255, 255, 0),
-1,
)
center_x, center_y = (
int(center_x * self.resized_width),
int(center_y * self.resized_height),
)
xc, yc = None, None
landmarks = side_results.pose_landmarks.landmark
self.pixel_distance = self.euclidean_distance(
top_point[0],
top_point[1],
center_x,
center_y,
)
if side_results.pose_landmarks:
left_hip = landmarks[LANDMARK_NAME_TO_INDEX["left_hip"]]
right_hip = landmarks[LANDMARK_NAME_TO_INDEX["right_hip"]]
center_point = (
(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__":
landmarker = Landmarker()