### Install pyopf Python Library Source: https://github.com/pix4d/pyopf/blob/main/README.md This command installs the core `pyopf` Python library using pip, making it available for use in Python projects. ```shell pip install pyopf ``` -------------------------------- ### Install pyopf with Command Line Tools Source: https://github.com/pix4d/pyopf/blob/main/README.md This command installs the `pyopf` library along with its additional command-line tool dependencies, enabling access to utilities like `opf_undistort` and `opf_crop`. ```shell pip install pyopf[tools] ``` -------------------------------- ### Load and Resolve OPF Project Data in Python Source: https://github.com/pix4d/pyopf/blob/main/README.md This Python example demonstrates how to load an OPF project file, resolve its internal references using `pyopf.resolve`, and then access specific data like the calibrated position and orientation of a camera by its unique ID. It includes error handling for missing calibration data. ```python from pyopf.io import load from pyopf.resolve import resolve from pyopf.uid64 import Uid64 # Path to the example project file. project_path = "spec/examples/project.opf" # We are going to search for the calibrated position of the camera with this ID camera_id = Uid64(hex = "0x2D1A1DE") # Load the json data and resolve the project, i.e. load the project items as named attributes. project = load(project_path) project = resolve(project) # Many objects are optional in OPF. If they are missing, they are set to None. if project.calibration is None: print("No calibration data.") exit(1) # Filter the list of calibrated cameras to find the one with the ID we are looking for. calibrated_camera = [camera for camera in project.calibration.calibrated_cameras.cameras if camera.id == camera_id] # Print the pose of the camera. if calibrated_camera: print("The camera {} is calibrated at:".format(camera_id), calibrated_camera[0].position) print("with orientation", calibrated_camera[0].orientation_deg) else: print("There is no camera with id: {} in the project".format(camera_id)) ``` -------------------------------- ### Set Custom Attribute on PyOPF Point Cloud Node in Python Source: https://github.com/pix4d/pyopf/blob/main/README.md This Python example illustrates how to open a GLTF point cloud using `pyopf.pointcloud.GlTFPointCloud`, generate a new NumPy array as a custom attribute, and assign it to a node's `custom_attributes` dictionary. It demonstrates handling cases where the `custom_attributes` dictionary might initially be `None`. ```python import numpy as np from pathlib import Path from pyopf.pointcloud import GlTFPointCloud pcl = GlTFPointCloud.open(Path('dense_pcl/dense_pcl.gltf')) # Generate a new point attribute as a random vector of 0s and 1s # The attribute must have one scalar per point new_attribute = np.random.randint(0, 2, size=len(pcl.nodes[0])) # The attribute must have the shape (number_of_points, 1) new_attribute = new_attribute.reshape((-1, 1)) # Supported types for custom attributes are np.float32, np.uint32, np.uint16, np.uint8 new_attribute = new_attribute.astype(np.uint32) # Set the new attribute as a custom attribute for the node # By default, nodes might be missing custom attributes, so the dictionary might have to be created if pcl.nodes[0].custom_attributes is not None: pcl.nodes[0].custom_attributes['point_class'] = new_attribute else: pcl.nodes[0].custom_attributes = {'point_class': new_attribute} pcl.write(Path('out/out.gltf')) ``` -------------------------------- ### Convert OPF Project to COLMAP Sparse Model Source: https://github.com/pix4d/pyopf/blob/main/README.md This tool converts an OPF project into a COLMAP sparse model, generating `cameras.txt`, `images.txt`, and `points3D.txt`. It supports copying images to a new directory while preserving the folder structure. Only calibrated projects with perspective cameras are supported. ```Shell opf2colmap project.opf ``` -------------------------------- ### Convert OPF Project to NeRF Transforms Source: https://github.com/pix4d/pyopf/blob/main/README.md This tool converts OPF projects to NeRF transform files, typically `transforms_train.json` and `transforms_test.json`, controlling the split with `--train-frac`. It also supports converting or copying input images to different formats or directories while preserving the directory layout. Only calibrated projects with perspective cameras are supported. ```Shell opf2nerf project.opf --output-extension ``` ```Shell opf2nerf project.opf --out-dir out_dir/ --nerfstudio ``` ```Shell opf2nerf project.opf --out-img-format png --out-img-dir ./images --no-camera-flip ``` -------------------------------- ### Convert OPF Project Point Clouds to LAS Source: https://github.com/pix4d/pyopf/blob/main/README.md This tool converts dense and sparse point clouds from an OPF project into the LAS format. It requires specifying an output directory for the generated LAS files. ```Shell opf2las path_to/project.opf --out-dir your_output_dir ``` -------------------------------- ### Convert OPF Project Point Clouds to PLY Source: https://github.com/pix4d/pyopf/blob/main/README.md This tool converts dense and sparse point clouds from an OPF project into the PLY format. It requires specifying an output directory for the generated PLY files. ```Shell opf2ply path_to/project.opf --out-dir your_output_dir ``` -------------------------------- ### Crop OPF Project by Region of Interest using Command Line Tool Source: https://github.com/pix4d/pyopf/blob/main/README.md This command-line tool crops an OPF project to preserve only the region of interest, as defined by the `ext_pix4d_region_of_interest` extension. It updates point clouds, cameras, and GCPs, discarding elements outside the ROI. The project must be calibrated and contain the ROI extension. ```shell opf_crop project_to_crop.opf output_directory ``` -------------------------------- ### Undistort Images in OPF Project using Command Line Tool Source: https://github.com/pix4d/pyopf/blob/main/README.md This command-line tool undistorts images within an OPF project. Undistorted images are saved in an `undistort` subdirectory relative to their original location. This operation is only supported for images captured with perspective cameras that have calibrated sensors. ```shell opf_undistort project.opf ``` -------------------------------- ### Compute Reprojection Error for GCPs in OPF Project Source: https://github.com/pix4d/pyopf/blob/main/README.md This Python script calculates the reprojection error of input Ground Control Points (GCPs) within calibrated cameras, using an OPF project as its input source. It helps evaluate the accuracy of camera calibration. ```Shell python examples/compute_reprojection_error.py --opf_path path_to/project.opf ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.