Skip to content

Commit

Permalink
Assert that image and depth image have equal shapes
Browse files Browse the repository at this point in the history
  • Loading branch information
Wiktor-99 committed Jul 15, 2024
1 parent 5cea2ea commit 1b09e9c
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions human_detector/human_detector/human_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,28 @@ def store_camera_info(self, info: CameraInfo):
if not self.camera_info_is_stored:
self.camera_info_is_stored = True

def are_rgb_image_same_size_as_depth_image(self):
rgb_image_height, rgb_image_width, _ = self.image.shape
depth_image_height, depth_image_width, _ = self.depth_image.shape

return rgb_image_height == depth_image_height and rgb_image_width == depth_image_width

def store_human_pose(self):
if not self.camera_info_is_stored or self.image is None or self.depth_image is None:
self.get_logger().error("No camera info or image or depth image are not stored")
self.get_logger().error(
"No camera info or image or depth image are not stored. Human will not be detected."
)
return

if not self.are_rgb_image_same_size_as_depth_image():
self.get_logger().error(
"Dimensions of rgb image and depth image are not equal. Human will not be detected."
)
return

hight, width, _ = self.image.shape
self.detected_landmarks = self.person_pose_estimator.process(self.image).pose_landmarks
x_pos_of_detected_person, y_pos_of_detected_person = \
self.get_position_of_human_in_the_image(self.detected_landmarks, width, hight)
self.get_position_of_human_in_the_image(self.detected_landmarks)

if x_pos_of_detected_person <= 0 or y_pos_of_detected_person <= 0:
return
Expand All @@ -133,7 +146,8 @@ def store_human_pose(self):
'z': mm_to_m(point_xyz[1])
}

def get_position_of_human_in_the_image(self, detected_landmarks: NamedTuple, width: int, height: int):
def get_position_of_human_in_the_image(self, detected_landmarks: NamedTuple):
height, width, _ = self.image.shape
x, y = 0, 0
if detected_landmarks:
landmarks = mp.solutions.pose.PoseLandmark
Expand Down

0 comments on commit 1b09e9c

Please sign in to comment.