# Untitled

unknown
python
7 months ago
1.7 kB
1
Indexable
Never
```import cv2
import numpy as np

# To check the values, go to: https://pixspy.com/
import cv2
import numpy as np

# Load the first mask to get the center's location in pixels

# Calculate the center of mass of the mask
center_x = int(M['m10'] / M['m00'])
center_y = int(M['m01'] / M['m00'])

# Print the center coordinates
print("Center coordinates: ({}, {})".format(center_x, center_y))

# # THIS IS ANOTHER WAY THAT USES THE BOUNDING BOX INSTEAD OF THE CENTER OF MASS

# # Find contours of the mask
# contours, _ = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

# # Compute the center of the bounding rectangle
# x, y, w, h = cv2.boundingRect(contours[0])
# center_x = x + w // 2
# center_y = y + h // 2

# # Print the center coordinates
# print("Center coordinates: ({}, {})".format(center_x, center_y))

import cv2

# Load the PNG depth image (assumed to be in 16-bit format)
print("Depth image shape:", depth_image.shape)
print("Depth image dtype:", depth_image.dtype)

# Get the shape of the depth image
height, width = depth_image.shape

# Assume you already have the center coordinates (center_x, center_y)
# Get the depth value at the center pixel
depth_value = depth_image[center_y, center_x]

# Print the depth value
print("Depth value at center pixel: ", depth_value)
```