示例#1
0
 def setUp(self):
     self.t = pcl.OctreePointCloudSearch_PointXYZI(0.1)
     pc = pcl.load_XYZI("tests" + os.path.sep +
                        "table_scene_mug_stereo_textured_noplane.pcd")
     self.t.set_input_cloud(pc)
     self.t.define_bounding_box()
     self.t.add_points_from_input_cloud()
示例#2
0
def test_pcd_read():
    TMPL = """# .PCD v.7 - Point Cloud Data file format
VERSION .7
FIELDS x y z
SIZE 4 4 4
TYPE F F F
COUNT 1 1 1
WIDTH %(npts)d
HEIGHT 1
VIEWPOINT 0.1 0 0.5 0 1 0 0
POINTS %(npts)d
DATA ascii
%(data)s"""

    a = np.array(np.mat(SEGDATA, dtype=np.float32))
    npts = a.shape[0]
    tmp_file = tempfile.mkstemp(suffix='.pcd')[1]
    with open(tmp_file, "w") as f:
        f.write(TMPL % {"npts": npts, "data": SEGDATA.replace(";", "")})

    p = pcl.load_XYZI(tmp_file)

    assert p.width == npts
    assert p.height == 1

    for i, row in enumerate(a):
        pt = np.array(p[i])
        ssd = sum((row - pt)**2)
        assert ssd < 1e-6

    assert_array_equal(p.sensor_orientation,
                       np.array([0, 1, 0, 0], dtype=np.float32))
    assert_array_equal(p.sensor_origin,
                       np.array([.1, 0, .5, 0], dtype=np.float32))
示例#3
0
    def get_single_pcd_info(self,single_pcd_path):
        single_pcd_path = single_pcd_path
        single_pcd_points = pcl.load_XYZI(single_pcd_path)
        #将点云数据转化为numpy格式
        single_pcd_points_np = single_pcd_points.to_array()
        #去掉一帧点云数据中无效的点
        single_pcd_points_np = self.remove_nan_data(single_pcd_points_np)
        #将点云数据转化为list格式
        #single_pcd_points_list =single_pcd_points.to_list()

        return single_pcd_points_np
示例#4
0
    def get_data(fname):
        short_name = fname.split('/')[-1]
        scan = pcl.load_XYZI(fname)
        xyzi = []
        for i in range(scan.width):
            xyzi.append(scan.__getitem__(i))
        xyzi = np.array(xyzi)
        coords = xyzi[:, :3]
        labels = xyzi[:, 3]
        labels = labels.reshape(-1, 1)

        return short_name, coords, labels
示例#5
0
def embed():
    parser = argparse.ArgumentParser()
    parser.add_argument('--checkpoint',
                        type=str,
                        required=True,
                        help='path to checkpoint file')
    parser.add_argument('--input',
                        type=str,
                        required=True,
                        help='path to input PCD file')
    parser.add_argument('--output', type=str, help='path to output file')
    parser.add_argument('--device',
                        type=str,
                        default='cuda',
                        help='trainng device')
    args = parser.parse_args()

    # ===============Create dataset===================

    pcs = pcl.load_XYZI(args.input)
    pcs_xyz = XYZRGB_to_XYZ(pcs)
    pcs_np = np.asarray(pcs_xyz)
    test_dataset = QdhInferenceDataset(cfg, mode='inference', pcs=pcs_np)

    # ===================Resume====================
    model, optimizer, start_epoch, scheduler = load_network(
        cfg, args.device, args.checkpoint)
    model.eval()

    # ======================Start==========================
    with torch.no_grad():
        test_loader = data.DataLoader(test_dataset,
                                      batch_size=1,
                                      num_workers=1,
                                      collate_fn=test_dataset.collate_fn,
                                      shuffle=False,
                                      drop_last=False)
        batch_data = next(iter(test_loader))
        inputs, selected_indices = batch_data
        inputs = make_cuda(inputs)
        preds = model(inputs)
        logits = preds
        logits = logits.transpose(1, 2).reshape(-1, cfg.num_classes)
        preds = logits.max(dim=1)[1].cpu().numpy()
        if args.output is not None:
            outpath = args.output
        else:
            outpath = os.path.join('results', os.path.basename(args.input))
            if not os.path.exists(os.path.dirname(outpath)):
                os.makedirs(os.path.dirname(outpath))
        visualize(preds, pcs_xyz, selected_indices, outpath)
        print('result is saved to {}'.format(outpath))
示例#6
0
 def testLoad(self):
     pc = pcl.load_XYZI("tests" + os.path.sep + "table_scene_mug_stereo_textured_noplane.pcd")
     self.t.set_input_cloud(pc)
     self.t.define_bounding_box()
     self.t.add_points_from_input_cloud()
     good_point = (0.035296999, -0.074322999, 1.2074)
     rs = self.t.is_voxel_occupied_at_point(good_point)
     self.assertTrue(rs)
     bad_point = (0.5, 0.5, 0.5)
     rs = self.t.is_voxel_occupied_at_point(bad_point)
     self.assertFalse(rs)
     voxels_len = 44
     self.assertEqual(len(self.t.get_occupied_voxel_centers()), voxels_len)
     self.t.delete_voxel_at_point(good_point)
     self.assertEqual(
         len(self.t.get_occupied_voxel_centers()), voxels_len - 1)
示例#7
0
import pcl
import pcl.pcl_visualization
import numpy as np

point_cloud = pcl.load_XYZI('point_cloud.pcd')
points = point_cloud.to_array()[:, :3]
points = points[points[:,2] < 200]
points = points[points[:,2] > -5]
points = points[points[:,1] > -2]
points = points[points[:,0] > -2]

point_cloud_temp = pcl.PointCloud()
point_cloud_temp.from_array(points)
pcl.save(point_cloud_temp, 'point_cloud_temp.ply', format='ply')
modified_point_cloud = pcl.load_XYZI('point_cloud_temp.ply')
visual = pcl.pcl_visualization.CloudViewing()

visual.ShowGrayCloud(modified_point_cloud, b'cloud')

flag = True
while flag:
    pass
end
    points_list = []
    
    for data in pointXYZI:
        intensity = int(data[3]) 
        print(intensity)
        float_rgb = rgb_to_float(Intensity_to_color(intensity))
        points_list.append([data[0], data[1], data[2], float_rgb])
    
    cloud_rgb.from_list(points_list)
    
    return cloud_rgb

    
if __name__ == "__main__":
    file_name = "frame_save_244.pcd"
    origin = pcl.load_XYZI("C:/Users/Administrator/Desktop/pcds/" + file_name)
    pointXYZRGB = XYZI_to_XYXRGB(origin)
    visual = pcl.pcl_visualization.CloudViewing()
    visual.ShowColorCloud(pointXYZRGB, b'cloud')
    










示例#9
0
        sys.exit()

    if input_dir[-1] == '/':
        index = input_dir[:-2].rfind('/')
    else:
        index = input_dir.rfind('/')
    output_dir = input_dir[:index]
    if transfer_type == 0:
        output_dir = os.path.join(output_dir, "Binary_pcd")
    else:
        output_dir = os.path.join(output_dir, "Ascii_pcd")

    if os.path.exists(output_dir) == False:
        os.makedirs(output_dir)

    print("Start to tranfer!")
    print("Output will save to ", output_dir)
    for filePath in os.listdir(input_dir):
        in_pcd_file_path = os.path.join(input_dir, filePath)
        out_pcd_file_path = os.path.join(output_dir, filePath)
        if in_pcd_file_path.split('.')[-1] != 'pcd':
            print("Error format file: ", filePath)
            print("Skip this file!")
            continue
        pt = pcl.load_XYZI(in_pcd_file_path, 'pcd')
        if transfer_type == 0:
            pcl.save(pt, out_pcd_file_path, 'pcd', True)
        else:
            pcl.save(pt, out_pcd_file_path, 'pcd', False)

    print("Done!")
示例#10
0
 def setUp(self):
     self.p = pcl.load_XYZI("tests" + os.path.sep +
                            "table_scene_mug_stereo_textured_noplane.pcd")
示例#11
0
 def setUp(self):
     self.p = pcl.load_XYZI("tests" + os.path.sep + "flydracyl.pcd")
示例#12
0
 def testSave(self):
     for ext in ["pcd", "ply"]:
         d = os.path.join(self.tmpdir, "foo." + ext)
         pcl.save(self.p, d)
         p = pcl.load_XYZI(d)
         self.assertEqual(self.p.size, p.size)
示例#13
0
 def setUp(self):
     self.p = pcl.load_XYZI("tests" + os.path.sep +
                            "table_scene_mug_stereo_textured_noplane.pcd")
     self.tmpdir = tempfile.mkdtemp(suffix='pcl-test')
示例#14
0
 def setUp(self):
     self.t = pcl.OctreePointCloudSearch_PointXYZI(0.1)
     pc = pcl.load_XYZI("tests" + os.path.sep + "table_scene_mug_stereo_textured_noplane.pcd")
     self.t.set_input_cloud(pc)
     self.t.define_bounding_box()
     self.t.add_points_from_input_cloud()
示例#15
0
文件: ex6.py 项目: jtpils/ais3d
    # Assign 1 to visualize the images and PCD
    show_images = 0

    # Iterate for every image
    for img_idx in range(1, len(testset)):
        # Get the real image index (used in file names etc.)
        img_real_id = testset.img_id_return(img_idx)

        #Delete the 0s before the number
        if img_real_id == '000000':
            pcd_id = '0'
        else:
            pcd_id = img_real_id.lstrip('0')  # without 0

        #Read Cloud & Convert it to array
        cloud = pcl.load_XYZI(os.path.join(pcd_dir, '{0}.pcd'.format(pcd_id)))
        points_array = np.asarray(cloud)

        #Read Calibration Matrices & Detected objects
        Tr_velo_to_cam, R0_rect, P2 = readCalibration(calib_dir, img_real_id)
        objects = readDetections(detection_dir, img_real_id)

        filtered_points_array = []

        # Show the boxes on the test image
        if show_images == 1:
            image = testset.pull_image(img_idx)
            for index in range(0, len(objects)):
                obj = objects[index]
                cv2.rectangle(image, (obj.xmin, obj.ymin),
                              (obj.xmax, obj.ymax), (0, 255, 0), 2)
示例#16
0
def read_pcd(path_file):
    pcd = pcl.load_XYZI(path_file)
    return pcd