Exemplo n.º 1
0
def test_e57(pano_scan):
    e57 = pye57.E57(pano_scan)  # read scan at index 0
    data = e57.read_scan(0)

    # 'data' is a dictionary with the point types as keys
    assert isinstance(data["cartesianX"], np.ndarray)
    assert isinstance(data["cartesianY"], np.ndarray)
    assert isinstance(data["cartesianZ"], np.ndarray)

    # other attributes can be read using:
    data = e57.read_scan(0, intensity=True, colors=True, row_column=True)
    assert isinstance(data["cartesianX"], np.ndarray)
    assert isinstance(data["cartesianY"], np.ndarray)
    assert isinstance(data["cartesianZ"], np.ndarray)
    assert isinstance(data["intensity"], np.ndarray)
    assert isinstance(data["colorRed"], np.ndarray)
    assert isinstance(data["colorGreen"], np.ndarray)
    assert isinstance(data["colorBlue"], np.ndarray)
    assert isinstance(data["rowIndex"], np.ndarray)
    assert isinstance(data["columnIndex"], np.ndarray)

    # the 'read_scan' method filters points using the 'cartesianInvalidState' field
    # if you want to get everything as raw, untransformed data, use:
    data_raw = e57.read_scan_raw(0)

    # writing is also possible, but only using raw data for now
    e57_write = pye57.E57("e57_file_write.e57", mode='w')
    e57_write.write_scan_raw(data_raw)

    # you can specify a header to copy information from
    e57_write.write_scan_raw(data_raw, scan_header=e57.get_header(0))

    # the ScanHeader object wraps most of the scan information:
    header = e57.get_header(0)
    print(header.point_count)
    print(header.rotation_matrix)
    print(header.translation)

    # all the header information can be printed using:
    for line in header.pretty_print():
        print(line)

    # the scan position can be accessed with:
    position_scan_0 = e57.scan_position(0)

    # the binding is very close to the E57Foundation API
    # you can modify the nodes easily from python
    imf = e57.image_file
    root = imf.root()
    data3d = root["data3D"]
    scan_0 = data3d[0]
    translation_x = scan_0["pose"]["translation"]["x"]
Exemplo n.º 2
0
def load_e57(
    file: str = "data/raw/CustomerCenter1 1.e57", ) -> Tuple[dict, dict]:
    """Return a dictionary with the point types as keys."""
    print(f"Loading e57 file {file}.")
    e57 = pye57.E57(file)

    # Get and clean-up header
    raw_header = e57.get_header(0)
    header = {}
    for attr in dir(raw_header):
        if attr[0:1].startswith("_"):
            continue
        try:
            value = getattr(raw_header, attr)
        except pye57.libe57.E57Exception:
            continue
        else:
            header[attr] = value

    header["pos"] = e57.scan_position(0)

    data = e57.read_scan_raw(0)
    # for key, values in data.items():
    #     assert isinstance(values, np.ndarray)
    #     assert len(values) == 151157671
    #     print(f"len of {key}: {len(values)} ")

    return data, header
def test_read_raw(e57_path):
    e57 = pye57.E57(e57_path)
    header = e57.get_header(0)
    fields = header.point_fields
    data = e57.read_scan_raw(0)
    assert sorted(fields) == sorted(data.keys())
    assert np.any(data["cartesianX"])
    assert len(data["cartesianX"]) == header.point_count
def test_unsupported_point_field(temp_e57_write):
    with pye57.E57(temp_e57_write, mode="w") as f:
        with pytest.raises(ValueError):
            data = {
                "cartesianX": np.random.rand(10),
                "bananas": np.random.rand(10)
            }
            f.write_scan_raw(data)
Exemplo n.º 5
0
def read_e57_with_pose(pano_scan, bTransform=True):
    e57 = pye57.E57(pano_scan)  # read scan at index 0
    data = e57.read_scan(0, colors=True)

    n_pts = data["cartesianX"].shape[0]
    colors = np.zeros((n_pts, 3))
    colors[:, 0] = data["colorRed"]
    colors[:, 1] = data["colorGreen"]
    colors[:, 2] = data["colorBlue"]

    points = np.zeros((n_pts, 3))
    points[:, 0] = data["cartesianX"]
    points[:, 1] = data["cartesianY"]
    points[:, 2] = data["cartesianZ"]

    imf = e57.image_file
    root = imf.root()
    data3d = root["data3D"]
    scan_0 = data3d[0]
    translation_x = scan_0["pose"]["translation"]["x"].value()
    translation_y = scan_0["pose"]["translation"]["y"].value()
    translation_z = scan_0["pose"]["translation"]["z"].value()

    rotation_x = scan_0["pose"]["rotation"]["x"].value()
    rotation_y = scan_0["pose"]["rotation"]["y"].value()
    rotation_z = scan_0["pose"]["rotation"]["z"].value()
    rotation_w = scan_0["pose"]["rotation"]["w"].value()

    rotation = [rotation_w, rotation_x, rotation_y, rotation_z]
    translation = [translation_x, translation_y, translation_z]
    q = Quaternion(rotation)
    R_scan = np.transpose(q.rotation_matrix)
    t_scan = -np.dot(R_scan, np.transpose(np.asarray(translation)))

    if (bTransform):
        points_scan_transformed = Transform_cloud(points, R_scan, t_scan)

        ## rotate 90 degree around x axis
        q_x90 = Quaternion(axis=[1, 0, 0], angle=np.pi / 2)
        points_scan_transformed_f = Transform_cloud(points_scan_transformed,
                                                    q_x90.rotation_matrix,
                                                    np.zeros(3))

        ## rotate 90 degree around y axis
        q_y90 = Quaternion(axis=[0, 1, 0], angle=np.pi / 2)
        points_scan_transformed_f = Transform_cloud(points_scan_transformed_f,
                                                    q_y90.rotation_matrix,
                                                    np.zeros(3))
    else:
        points_scan_transformed_f = points

    return points_scan_transformed_f, colors, R_scan, t_scan
def test_read_write_single_scan(e57_path, temp_e57_write):
    e57 = pye57.E57(e57_path)
    header_source = e57.get_header(0)
    with pye57.E57(temp_e57_write, mode="w") as e57_write:
        raw_data_0 = e57.read_scan_raw(0)
        e57_write.write_scan_raw(raw_data_0,
                                 rotation=header_source.rotation,
                                 translation=header_source.translation)
    scan_0 = pye57.E57(e57_path).read_scan_raw(0)
    written = pye57.E57(temp_e57_write)
    header = written.get_header(0)
    assert np.allclose(header.rotation, header_source.rotation)
    assert np.allclose(header.translation, header_source.translation)
    scan_0_written = written.read_scan_raw(0)
    fields = "cartesianX cartesianY cartesianZ intensity rowIndex columnIndex cartesianInvalidState".split(
    )
    for field in fields:
        assert np.allclose(scan_0[field], scan_0_written[field])

    scan_0 = e57.read_scan(0)
    scan_0_written = written.read_scan(0)
    for field in scan_0:
        assert np.allclose(scan_0[field], scan_0_written[field])
def test_copy_file(e57_path, temp_e57_write):
    e57 = pye57.E57(e57_path)
    with pye57.E57(temp_e57_write, mode="w") as f:
        for scan_id in range(e57.scan_count):
            header = e57.get_header(scan_id)
            data = e57.read_scan_raw(scan_id)
            f.write_scan_raw(data, scan_header=header)
            header_written = f.get_header(scan_id)
            assert header_written.guid
            assert header_written.temperature == header_written.temperature
            assert header_written.relativeHumidity == header_written.relativeHumidity
            assert header_written.atmosphericPressure == header_written.atmosphericPressure
            assert header_written.rowMinimum == header.rowMinimum
            assert header_written.rowMaximum == header.rowMaximum
            assert header_written.columnMinimum == header.columnMinimum
            assert header_written.columnMaximum == header.columnMaximum
            assert header_written.returnMinimum == header.returnMinimum
            assert header_written.returnMaximum == header.returnMaximum
            assert header_written.intensityMinimum == header.intensityMinimum
            assert header_written.intensityMaximum == header.intensityMaximum
            assert header_written.xMinimum == header.xMinimum
            assert header_written.xMaximum == header.xMaximum
            assert header_written.yMinimum == header.yMinimum
            assert header_written.yMaximum == header.yMaximum
            assert header_written.zMinimum == header.zMinimum
            assert header_written.zMaximum == header.zMaximum
            assert np.allclose(header_written.rotation, header.rotation)
            assert np.allclose(header_written.translation, header.translation)
            assert header_written.acquisitionStart_dateTimeValue == header.acquisitionStart_dateTimeValue
            assert header_written.acquisitionStart_isAtomicClockReferenced == header.acquisitionStart_isAtomicClockReferenced
            assert header_written.acquisitionEnd_dateTimeValue == header.acquisitionEnd_dateTimeValue
            assert header_written.acquisitionEnd_isAtomicClockReferenced == header.acquisitionEnd_isAtomicClockReferenced
            # todo: point groups
            # header.pointGroupingSchemes["groupingByLine"]["idElementName"].value()
            # header.pointGroupingSchemes["groupingByLine"]["groups"]

        assert f.scan_count == e57.scan_count
def test_e57_mode_error(temp_e57_write):
    with pytest.raises(ValueError):
        f = pye57.E57(temp_e57_write, mode="pasta")
def test_scan_position(e57_path):
    e57 = pye57.E57(e57_path)
    print(e57.scan_position(0))
    assert np.allclose(
        e57.scan_position(3),
        np.array([[3.01323456e+05, 5.04260184e+06, 1.56040279e+01]]))
def test_read_color_absent(e57_path):
    e57 = pye57.E57(e57_path)
    with pytest.raises(ValueError):
        data = e57.read_scan(0, colors=True)
def test_read_xyz(e57_path):
    e57 = pye57.E57(e57_path)
    xyz = e57.read_scan(0)
    assert np.any(xyz)
Exemplo n.º 12
0
import numpy as np
import pye57  # using this library - https://github.com/davidcaron/pye57
# if pip install pye57 fails on mac os / linux, just install xerces-c lib (f.e. - brew install xerces-c)

# read 3D scan of the site
e57 = pye57.E57("data/CustomerCenter1 1.e57")

# print out some file header info
# the ScanHeader object wraps most of the scan information:
print('----------------------------------------------')
header = e57.get_header(0)
print(header.point_count)
print(header.rotation_matrix)
print(header.translation)
# all the header information can be printed using:
for line in header.pretty_print():
    print(line)
print('----------------------------------------------')

#
# neither of these 2 read scans below work :( at index 0
#
# read scan at index 0
# data = e57.read_scan(0)
# read scan at index 0 with colors and intensity information
# data = e57.read_scan(0, intensity=True, colors=True)

# turned out that there are 2 rows to scan in data
print(e57.scan_count)

# the 'read_scan' method filters points using the 'cartesianInvalidState' field
Exemplo n.º 13
0
import numpy as np
import pye57
import pickle

e57 = pye57.E57("e57_file.e57")

data_raw_0 = e57.read_scan_raw(0)

x_tr = np.array([
    data_raw_0["cartesianX"], data_raw_0["cartesianY"],
    data_raw_0["cartesianZ"]
])
x = x_tr.transpose()

with open("points_raw_0.pkl", "wb") as f:
    pickle.dump(x, f)

with open('points_raw_0.pkl', 'rb') as f:
    x_load = pickle.load(f)
    print(x_load.shape)
Exemplo n.º 14
0
import shapefile
import pye57
import wget
import tempfile

with tempfile.TemporaryDirectory() as temp:
    filename = wget.download(
        'https://phoenixnap.dl.sourceforge.net/project/e57-3d-imgfmt/'
        'E57Example-data/Trimble_StSulpice-Cloud-50mm.e57',
        out=temp)
    e57 = pye57.E57(filename)
    data = e57.read_scan_raw(0)
    with shapefile.Writer("Trimble_StSulpice-Cloud-50mm") as w:
        w.field('name', 'C')
        w.multipointz(
            list(
                zip(data["cartesianX"], data["cartesianY"],
                    data["cartesianZ"])))
        w.record(name="pointcloud")
Exemplo n.º 15
0
import pye57
import sys
sys.path.append('/home/sadams/green/greenUtilities')

import numpy as np

e57 = pye57.E57("/home/sadams/sites/MezSnake/MezSnake.e57")

# the ScanHeader object wraps most of the scan information:
header = e57.get_header()

# all the header information can be printed using:
for line in header.pretty_print():
    print(line)

data = e57.read_scan(0, colors = True, ignore_missing_fields = True)
print(data.keys())
x = data['cartesianX']
y = data['cartesianY']
z = data['cartesianZ']

red = data['colorRed']
green = data['colorGreen']
blue = data['colorBlue']

points = np.hstack((
	np.expand_dims(x, axis = 1),
	np.expand_dims(y, axis = 1),
	np.expand_dims(z, axis = 1), ))

colors = np.hstack((
Exemplo n.º 16
0
import numpy as np
import pye57
import cv2
from scipy.spatial.transform import Rotation

if __name__ == "__main__":

    e57 = pye57.E57("datasets/file.e57")
    imf = e57.image_file
    root = imf.root()

    print("File loaded successfully!")
    if not root['images2D']:
        print("File contains no 2D images. Exiting...")

    for image_idx, image2D in enumerate(root['images2D']):
        print("\n\n#########################################")
        print("## Camera " + str(image_idx))

        # Get extrinsic matrix
        tx = image2D['pose']['translation']['x'].value()
        ty = image2D['pose']['translation']['y'].value()
        tz = image2D['pose']['translation']['z'].value()

        t = np.array([tx, ty, tz])

        rx = image2D['pose']['rotation']['x'].value()
        ry = image2D['pose']['rotation']['y'].value()
        rz = image2D['pose']['rotation']['z'].value()
        rw = image2D['pose']['rotation']['w'].value()