Skip to content

Commit

Permalink
GMM cleanup recommended by Jamie (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
marinagmoreira authored Feb 28, 2024
1 parent a618e88 commit 2d50941
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 69 deletions.
24 changes: 0 additions & 24 deletions anomaly/gmm-change-detection/scripts/gmm/gmm_change_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,6 @@ def gmm_change_detection(
n_appearances=0,
):

# Path to input data (.pk for pickled GMMs, PCL file,
# or bag files cropped to same positions at different times)

# input1 = './data/ground_truth/ground_truth_run5.pcd'
# input2 = './data/ground_truth/ground_truth_run4.pcd'

# input2 = "./data/single_frame_bags/20230313_1901_survey_no_bag_panorama_precut.bag"
# input1 = "./data/single_frame_bags/20230313_1908_survey_bag_panorama_precut.bag"

# input1 = './data/single_frame_bags/run5_astrobee.bag'
# input2 = './data/single_frame_bags/run1_astrobee.bag'

# input1 = './data/image_reconstruction/run5.pcd'
# input2 = './data/image_reconstruction/run2.pcd'

# input1 = './saved_models/fake_data_t0_1.pk'
# input2 = './saved_models/fake_data_t1_1.pk'

# input1 = './saved_models/20230313_1901_survey_no_bag_panorama_precut_1.pk'
# input2 = './saved_models/20230313_1908_survey_bag_panorama_precut_1.pk'

# input1 = 'data/image_reconstruction/run5.pcd'
# input2 = 'data/image_reconstruction/run4.pcd'

# Get file extension
ext = os.path.splitext(os.path.basename(input1))[1]
current_dir = os.getcwd()
Expand Down
45 changes: 0 additions & 45 deletions anomaly/gmm-change-detection/scripts/gmm/preprocess_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,8 @@

# See https://stackoverflow.com/questions/39772424
def convert_pc2_pcl(data):

# # Convert the PointCloud2 message to a list of points
# points = list(sensor_msgs.read_points(msg, field_names=("x", "y", "z"), skip_nans=True))

# data.__class__ = sensor_msgs.msg._PointCloud2.PointCloud2
# offset_sorted = {f.offset: f for f in data.fields}
# data.fields = [f for (_, f) in sorted(offset_sorted.items())]
# Conversion from PointCloud2 msg to np array.
np_points = ros_numpy.point_cloud2.pointcloud2_to_xyz_array(data, remove_nans=True)
# np_points=np.zeros((pc.shape[0],3))

# height = pc.shape[0]
# if len(pc.shape) == 1: # Unordered PC2 structure
# np_points = np.zeros((height, 3), dtype=np.float32)
# np_points[:, 0] = np.resize(pc["x"], height)
# np_points[:, 1] = np.resize(pc["y"], height)
# np_points[:, 2] = np.resize(pc["z"], height)

# else: # Ordered PC2 structure
# width = pc.shape[1]
# np_points = np.zeros((height * width, 3), dtype=np.float32)
# np_points[:, 0] = np.resize(pc["x"], height * width)
# np_points[:, 1] = np.resize(pc["y"], height * width)
# np_points[:, 2] = np.resize(pc["z"], height * width)

return np_points

Expand Down Expand Up @@ -191,29 +169,6 @@ def read_pc2_msgs(bagfile):
return merged_pcl


# # Process data from bagfile
# def read_pc2_msgs(bagfile):


# for topic, msg, t in rosbag.Bag(bagfile).read_messages():
# if topic == "/hw/depth_haz/extended/amplitude_int":
# np_im = ros_numpy.image.image_to_numpy(msg)
# data = Image.fromarray(np_im)

# if (
# topic == "/hw/depth_haz/points"
# or topic == "/hw/depth_haz/points/ground_truth"
# ):
# p = convert_pc2_pcl(msg)
# np_arr = filter_pcl(p)

# if "data" in locals():
# data.show()
# data.save("image.png")
# return np_arr
# return np_arr


# Process PCD point cloud directly
def read_ply(pcdfile):

Expand Down
19 changes: 19 additions & 0 deletions anomaly/gmm-change-detection/scripts/gmm/visualization.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
#!/usr/bin/env python
# Copyright (c) 2017, United States Government, as represented by the
# Administrator of the National Aeronautics and Space Administration.
#
# All rights reserved.
#
# The "ISAAC - Integrated System for Autonomous and Adaptive Caretaking
# platform" software is licensed under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

# Based on the GMM visualization code:
# https://github.com/sitzikbs/gmm_tutorial/blob/master/visualization.py
# with modifications to accomodate using the model data
Expand Down

0 comments on commit 2d50941

Please sign in to comment.