Skip to content

Commit

Permalink
refactor: cleanup cv2_img.
Browse files Browse the repository at this point in the history
  • Loading branch information
jws-1 committed Apr 18, 2024
1 parent 5922f50 commit 56711d3
Showing 1 changed file with 0 additions and 39 deletions.
39 changes: 0 additions & 39 deletions common/helpers/cv2_img/src/cv2_img/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import rospy
import numpy as np
import ros_numpy as rnp

from PIL import Image
from sensor_msgs.msg import Image as SensorImage
Expand Down Expand Up @@ -65,47 +64,9 @@ def msg_to_cv2_img(msg: SensorImage):
img = np.array(img)
img = img[:, :, ::-1].copy()

rospy.logwarn('shape of the image: ' + str(img.shape))

return img


# pcl_xyz = rnp.point_cloud2.pointcloud2_to_xyz_array(pcl_msg, remove_nans=False)
def pcl_msg_to_xyz(pcl_msg):
pcl_xyz = rnp.point_cloud2.pointcloud2_to_xyz_array(pcl_msg, remove_nans=False)

rospy.logwarn('shape of the image: ' + str(pcl_xyz.shape))

return pcl_xyz


def pcl_msg_to_cv2(pcl_msg):
"""
Constructs a cv2 image from a PointCloud2 message.
Parameters
----------
pcl_msg : sensor_msgs/PointCloud2
Input pointcloud (organised)
Returns
-------
np.array : cv2 image
"""

# Extract rgb image from pointcloud
frame = np.fromstring(pcl_msg.data, dtype=np.uint8)
frame = frame.reshape(pcl_msg.height, pcl_msg.width, 32)
frame = frame[:,:,16:19]

# Ensure array is contiguous
frame = np.ascontiguousarray(frame, dtype=np.uint8)

rospy.logwarn('shape of the image: ' + str(frame.shape))

return frame


def extract_mask_region(frame, mask, expand_x=0.5, expand_y=0.5):
"""
Extracts the face region from the image and expands the region by the specified amount.
Expand Down

0 comments on commit 56711d3

Please sign in to comment.