コード例 #1
0
def main():
    print('start!')
    filename = sys.argv[1]
    v,f = util.loadPLY(filename)
    asa = fill_holes(v)
    print(asa)
    print('finished!')
コード例 #2
0
def main():
    filename = sys.argv[1]
    v, _ = util.loadPLY(filename)
    v = np.array(v)
    for _ in range(100):
        v = fit_plane_LSE_RANSAC(v)
        if v.shape[0] < 500:
            return
    print('finished!')
コード例 #3
0
        tuple(p) for p in numpy.round((cloud[:, :3] / resolution)).astype(int)
    ]
    voxel_set = set()
    downsampled_cloud = []
    for i in range(len(cloud)):
        if not voxel_coordinates[i] in voxel_set:
            voxel_set.add(voxel_coordinates[i])
            downsampled_cloud.append(cloud[i])
    return numpy.array(downsampled_cloud)


dirname = sys.argv[1]  #directory containing separate raw scans
building_name = sys.argv[2]
output_dir = dirname + "/.."
scans = []
filelist = []
filelist.extend(glob.glob("%s/*.ply" % dirname))
filelist = sorted(filelist)
for s in filelist:
    pcd, _ = loadPLY(s)
    print(s, pcd.shape)
    scans.append(pcd)

for L in range(1, len(scans)):
    for l in itertools.combinations(range(len(scans)), L):
        stacked = numpy.vstack([scans[i] for i in l])
        stacked = downsample(stacked, 0.01)
        output_file = '%s/%s_real%s.ply' % (output_dir, building_name, ''.join(
            [str(i) for i in l]))
        savePLY(output_file, stacked)
コード例 #4
0
import numpy

import sys

sys.path.append('Hole_filling')

from util import loadPLY, savePLY

from HoleDetection import fill_holes

points, _ = loadPLY('./Data/02_pettit_input.ply')

points = points[:, :6]
print(len(points[0, :]))

print('Loaded', len(points), 'points')

points_XYZ = points[:, [0, 2, 1]]  #swap Y&Z coordinates

synthetic_points_XYZ = fill_holes(points_XYZ,
                                  max_circumradius=0.7,
                                  max_ratio_radius_area=0.02,
                                  distance=0.01)

print('Created', len(synthetic_points_XYZ), 'synthetic points')

synthetic_points_XYZ = synthetic_points_XYZ[:, [0, 2,
                                                1]]  #swap Y&Z coordinates

synthetic_points = numpy.zeros((len(synthetic_points_XYZ), 6))
コード例 #5
0
        return zx_depth_image, zx_rgb_image

    def generate_ortho_projection(self, pc, bounding_box):
        #sample a image based on density
        sampled_image = self.sample_image(pc, bounding_box)

        #scale and pad to target image size

if __name__ == '__main__':
    test_filename = '01_mason_east' if len(sys.argv) < 2 else sys.argv[1]
    convert3Dto2D = True if len(sys.argv) >= 3 else False

    if convert3Dto2D:
        ### 3D point cloud to 2D projection ###
        # load pcd point cloud
        test_pc, _ = loadPLY('../input/%s.ply' % test_filename)
        #flip z axis
        test_pc[:, 2] = -test_pc[:, 2]
        print('loaded point cloud', test_pc.shape)

        #calculate center and half_xyz
        min_xyz = test_pc[:, :3].min(axis=0)
        max_xyz = test_pc[:, :3].max(axis=0)
        center = 0.5 * (min_xyz + max_xyz)
        half_xyz = 0.5 * (max_xyz - min_xyz) + 0.5
        density = 50.0
        print('center', center)
        print('half_xyz', half_xyz)
        print('density', density)
        #save parameters to text file
        f = open('param_%s.txt' % test_filename, 'w')
コード例 #6
0
import skimage.measure
import numpy
from util import loadPLY, savePLY, saveVoxels
import sys
import tensorflow as tf

if len(sys.argv) < 3:
    print('Usage: python ply2sdf.py input.ply output.tfrecords')
    sys.exit(1)

V, _ = loadPLY(sys.argv[1])
voxel_scale = 0.188
#voxel_scale = 0.047
offset = V[:, :3].min(axis=0)
V[:, :3] -= offset
#voxellize
voxel_array = numpy.array(
    list(set([tuple(t) for t in (V[:, :3] / voxel_scale).astype(int)])))
bbox = voxel_array.max(axis=0) - voxel_array.min(axis=0) + 2
voxels = numpy.ones(bbox) * 1.5
voxels[voxel_array[:, 0], voxel_array[:, 1], voxel_array[:, 2]] = 0.5
print('voxels', voxels.shape)

with tf.python_io.TFRecordWriter(sys.argv[2]) as writer:
    target_sem = numpy.zeros(numpy.prod(voxels.shape),
                             dtype=numpy.uint8).flatten().tobytes()
    print(target_sem)
    out_feature = {
        'target_sem':
        tf.train.Feature(bytes_list=tf.train.BytesList(value=[target_sem])),
        'input_sdf/dim':
コード例 #7
0
import numpy
import sys
from util import loadPLY, savePLY
import os

gt_filename = sys.argv[1]  #ground truth combined point cloud
building_name = sys.argv[2]  #mason_east
pcd, _ = loadPLY(gt_filename)
print(gt_filename, pcd.shape)
minDims = pcd[:, :3].min(axis=0)
maxDims = pcd[:, :3].max(axis=0)

N = 20
for i in range(N):
    #create an interval between 10% and 90% of extent
    r1, r2 = numpy.random.random(2) * 0.8 + 0.1
    x1 = minDims[0] + (maxDims[0] - minDims[0]) * min(r1, r2)
    x2 = minDims[0] + (maxDims[0] - minDims[0]) * max(r1, r2)
    r1, r2 = numpy.random.random(2) * 0.8 + 0.1
    z1 = minDims[2] + (maxDims[2] - minDims[2]) * min(r1, r2)
    z2 = minDims[2] + (maxDims[2] - minDims[2]) * max(r1, r2)
    xmask = numpy.logical_or(pcd[:, 0] < x1, pcd[:, 0] > x2)
    zmask = numpy.logical_or(pcd[:, 2] < z1, pcd[:, 2] > z2)
    output = pcd[numpy.logical_or(xmask, zmask)]
    output_file = '%s/%s_synthetic%02d.ply' % (os.path.dirname(gt_filename),
                                               building_name, i)
    savePLY(output_file, output)
コード例 #8
0
import numpy
from util import loadPLY
import sys
numpy.random.seed(0)

if len(sys.argv) < 3:
    print("Usage: python get_accuracy.py ground_truth.ply prediction.ply")
    sys.exit(1)

ground_truth_points, _ = loadPLY(sys.argv[1])
predicted_points, _ = loadPLY(sys.argv[2])

#normalize color to 0->1
ground_truth_points[:, 3:6] /= 255.0
predicted_points[:, 3:6] /= 255.0

#randomly shuffle points so that voxels can be sampled non-deterministically
numpy.random.shuffle(ground_truth_points)
numpy.random.shuffle(predicted_points)

voxel_resolution = 0.05
ground_truth_voxels = {}
predicted_voxels = {}
voxel_coordinates = numpy.round(
    (ground_truth_points[:, :3] / voxel_resolution)).astype(int)
for i in range(len(ground_truth_points)):
    k = tuple(voxel_coordinates[i])
    if not k in ground_truth_voxels:
        ground_truth_voxels[k] = ground_truth_points[i, :]

voxel_coordinates = numpy.round(
コード例 #9
0
    train_partial_folder = '%s/train/partial/%s/' % (base_path, sceneID)
    val_gt_folder = '%s/val/gt/%s/' % (base_path, sceneID)
    val_partial_folder = '%s/val/partial/%s/' % (base_path, sceneID)
    if not os.path.isdir(train_gt_folder):
        os.mkdir(train_gt_folder)
    if not os.path.isdir(train_partial_folder):
        os.mkdir(train_partial_folder)
    if not os.path.isdir(val_gt_folder):
        os.mkdir(val_gt_folder)
    if not os.path.isdir(val_partial_folder):
        os.mkdir(val_partial_folder)

    for s in os.listdir(input_folder):
        if s.endswith('.ply'):
            if s.endswith('input.ply'):
                p, _ = loadPLY(input_folder + s)
                p, c, o = downsample(p)
                val_scale_offset.append([c] + list(o))
                val_list.append('%s/%s' % (sceneID, s.replace('.ply', '')))
                saveH5(val_partial_folder + s.replace('ply', 'h5'), p)
            elif s.endswith('gt.ply'):
                gt, _ = loadPLY(input_folder + s)
                gt, _, _ = downsample(gt)
                saveH5(val_gt_folder + s.replace('gt.ply', 'input.h5'), gt)
            else:
                train.append(s)
    total_train += len(train)

    for t in train:
        print(T, t)
        p, _ = loadPLY(input_folder + t)