-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ply #1829
Draft
smathermather
wants to merge
2
commits into
OpenDroneMap:master
Choose a base branch
from
smathermather:fix_ply
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Fix ply #1829
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# fix_ply.py | ||
|
||
Use to translate a modified ply into a compatible format for subsequent steps in ODM. Via Jaime Chacoff, https://community.opendronemap.org/t/edited-point-cloud-with-cloudcompare-wont-rerun-from-odm-meshing/21449/6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import os | ||
from plyfile import PlyData, PlyElement, PlyProperty | ||
import open3d as o3d | ||
import numpy as np | ||
|
||
|
||
def pcd_ascii_to_binary_ply(_ply_file: str, _binary_ply: str) -> None: | ||
""" Converts a .ply saved as ASCII format to a .ply saved with binary format and properties compatible with ODM""" | ||
|
||
ply_data: PlyData = PlyData.read(_ply_file) | ||
|
||
new_elements: list[PlyElement] = [] | ||
|
||
for element in ply_data.elements: | ||
if 'scalar_views' in element.data.dtype.names: | ||
new_dtype: list[tuple[str, str]] = [] | ||
for name in element.data.dtype.names: | ||
if name == 'scalar_views': | ||
new_dtype.append(('views', 'u1')) | ||
else: | ||
new_dtype.append((name, element.data.dtype[name])) | ||
|
||
new_data = np.empty(element.data.shape, dtype=new_dtype) | ||
|
||
for name in element.data.dtype.names: | ||
if name == 'scalar_views': | ||
new_data['views'] = element.data[name].astype('u1') | ||
else: | ||
new_data[name] = element.data[name] | ||
|
||
new_element = PlyElement.describe(new_data, element.name) | ||
else: | ||
new_element = PlyElement.describe(element.data, element.name) | ||
|
||
new_elements.append(new_element) | ||
|
||
new_ply_data = PlyData(new_elements, text=False) | ||
|
||
with open(_binary_ply, 'wb') as f: | ||
new_ply_data.write(f) | ||
|
||
|
||
def view_point_cloud(_input_ply: str) -> None: | ||
pcd = o3d.io.read_point_cloud(_input_ply) | ||
o3d.visualization.draw_geometries([pcd]) | ||
|
||
|
||
if __name__ == '__main__': | ||
|
||
# Parameters | ||
base: str = os.path.join('D:\\', '01_droneo', 'DJI_202407311545_024', 'odm_filterpoints') | ||
ply_file: str = os.path.join(base, 'point_cloud_ascii.ply') | ||
binary_ply_file: str = os.path.join(base, 'point_cloud.ply') | ||
|
||
if not os.path.isfile(ply_file): | ||
raise "File doesn't exist" | ||
|
||
pcd_ascii_to_binary_ply(ply_file, binary_ply_file) | ||
|
||
view_point_cloud(binary_ply_file) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are pretty specific hard-coded paths; should this program be modified to be a bit more generic before merging?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For sure. I was hoping to get permission from Jaime before proceeding with edits (originally posted here). Otherwise, I'll just re-write from the ground up using a similar approach.