배경 제거
1. 베이스라인 생성
2. 배경 제거 (bg_helper.py)
import sys
sys.path.append("/workspace/include")
import pcl_helper
import filter_helper
import pickle
import numpy as np
import pcl
import pcl_msg
import rospy
from sensor_msgs.msg import PointCloud2
import sensor_msgs.point_cloud2 as pc2
baselinefile = "baseline.pkl"
leaf_size = 0.1
print("serchPointNP Loaded : {}".format(baselinefile))
pkl_file = open(baselinefile, 'rb')
arr = pickle.load(pkl_file)
searchPoint = pcl.PointCloud()
searchPoint.from_array(arr)
print("Normal Baseline point {}".format(searchPoint))
baseline = filter_helper.do_voxel_grid_downssampling(searchPoint,leaf_size)
print("Voxeled Basedline point {}".format(searchPoint))
def background_removal(daytime):
resolution = 0.5
octree = baseline.make_octreeChangeDetector(resolution)
octree.add_points_from_input_cloud ()
octree.switchBuffers ()
daytime = pcl_helper.XYZRGB_to_XYZ(daytime)
octree.set_input_cloud(daytime)
octree.add_points_from_input_cloud ()
newPointIdxVector = octree.get_PointIndicesFromNewVoxels ()
daytime.extract(newPointIdxVector)
result = np.zeros((len(newPointIdxVector)+1, 3), dtype=np.float32)
for i in range(0, len(newPointIdxVector)):
result[i][0] = daytime[newPointIdxVector[i]][0]
result[i][1] = daytime[newPointIdxVector[i]][1]
result[i][2] = daytime[newPointIdxVector[i]][2]
pc = pcl.PointCloud(result)
cloud = pcl_helper.XYZ_to_XYZRGB(pc,[255,255,255])
return cloud
"""
def callback(input_ros_msg):
pcl_xyzrgb = pcl_helper.ros_to_pcl(input_ros_msg) #ROS 메시지를 PCL로 변경
pcl_xyz = pcl_helper.XYZRGB_to_XYZ(pcl_xyzrgb)
pcl_xyzrgb = background_removal(pcl_xyz, searchPoint)
bg_ros_msg = pcl_helper.pcl_to_ros(pcl_xyzrgb) #PCL을 ROS 메시지로 변경
pub_bg = rospy.Publisher("/velodyne_bg", PointCloud2, queue_size=1)
pub_bg.publish(bg_ros_msg)
"""