agisoft-llc / metashape-scripts Goto Github PK
View Code? Open in Web Editor NEWPython scripts for Metashape (former PhotoScan)
License: MIT License
Python scripts for Metashape (former PhotoScan)
License: MIT License
I found this support article: https://agisoft.freshdesk.com/support/solutions/articles/31000158881-style-transfer-for-3d-model
But the Script is not longer available for download > https://github.com/agisoft-llc/photoscan-scripts/blob/master/src/model_style_transfer.py
Please update the support article. Is style transfer still possible?
Would it be possible to add an "Export Images" checkbox in between "Use localframe" and "Image quality" options?
This would be set to true by default but if you need to quickly export the camera files after modifying something then you don't need to export the undistorted images again.
I've duplicated and modified the script by removing the image export params which works, but I'm having trouble editing the script and adding it to the script options, having it included will be very useful.
I'm running into an issue while testing creating a script similar to those posted here (with the GUI add-ons).
If I import a library (usually one with my utility functions) in my script that is loaded, notice an issue in my code, and then run the script again (creating a second entry in the menu bar, but it's ok for testing), it loads the imported library again as well. This seems to create a mess if I do it a few times in a row with things overwriting each other in a weird manner, but I can't figure out how to stop it.
Right now my code is messy with everything in the single script file to avoid this, but I'd like to know how to compartmentalize it while still being able to test it in the GUI without reopening Metashape each time.
Any suggestions?
Is it possible to add some code to be able to export a dense cloud instead? It should be more correct for where to calculate splats?
with latest version 1.8.3, script https://github.com/agisoft-llc/metashape-scripts/blob/master/src/save_estimated_reference.py returns an error when calling the getAntennaTransform() function.
The problem seems to be that sensor.antenna.location_ref and sensor.antenna.rotation_ref return None in latest version while it was returning a Vector in previous versions, see attachment comparing 1.7.3 and 1.8.3 behavior...
Modify message
Hi, can you share a script of the full process for 3d reconstruction. Maybe the functions are as follows:
In the tool panel -> Workflow → add photos (from a folder)
In the tool panel -> Workflow -> align photos :
In the tool panel -> Workflow -> Build dense cloud :
In the tool panel -> Workflow -> Build Mesh:
In the tool panel -> Workflow -> Build texture:
File → Export → Export mesh→ Export JPEG / TIFF / PNG
or give some detailed explannation for how to use the python API to finish these functions ?
Thanks !
I know how to add markers, but I have no idea how to place markers on the photos.
I debugged a code, and printed gcp errors individually, i want to know the unit of these errors.
GCP 0 - RMSE_X: 0.213748803, RMSE_Y: 0.285612156, RMSE_Z: 0.000000000
GCP 1 - RMSE_X: 0.672572103, RMSE_Y: 0.653956691, RMSE_Z: 0.000000000
GCP 2 - RMSE_X: 0.649858466, RMSE_Y: 0.552218275, RMSE_Z: 0.000000000
GCP 3 - RMSE_X: 0.223301913, RMSE_Y: 0.362567542, RMSE_Z: 0.000000000
I think these are in pixels, if so how to convert them in meters.Also i want the results in UTM co-ordinate system only.
I'm trying to run the footprints to shapes script on older aerial imagery processed using the fiducial marks. I've replaced line 48 to get the pixel coordinates (rounded to the nearest integer) of the fiducial marks in the four outer corners, but the process on line 49 produces coordinates that form a much smaller footprint, often with coordianates that are nearly on top of each other. The script works great on older film imagery I've rotated and cropped in photoshop, so I'm thinking I may need another translational step to account for image rotation and scaling based on the fiducial marks? Any suggestions? FYI, I've been trying this in 1.5.2 and 1.5.3
Thanks.
Maybe I'm trying to use it incorrectly but it works great to build the mesh once I have my dense cloud. Is there a method to build the dense cloud in the chunks using this script? It just duplicates my chunk once and doesn't build a dense cloud
line 120 raises the exception:
`AttributeError: 'Metashape.NetworkClient' object has no attribute 'resumeBatch'
I haven't tested older versions, but according to the release notes that method was removed in 1.8.0 so presumably it's been broken for the entire 1.8 series.
setBatchPaused seems to be the replacement for this method and changing it to use that fixes the issue.
Hello,
we are trying to use the footprints_to_shapes.py script, but generated footprints are not correct.
The main case where corners are unproject from model fails for many pictures (we are using a model generated from a very sparse point cloud ~ 75 m step with a bounding box that is much wider than the project bouding box as we just need rough footprints, so we would expect that pickpoint is always able to return a ray intersection.)
The fallover case were corners are unprojected from point_cloud do not fai (always return a value)l, but results seems wrong and the resulting footprints do not macth reality at all.
Do you have more details about the pickPont API for both model and dense_cloud ?
Regards
Hi I want to use - metashape-scripts - detect_objects.py
I installed everything properly, built an orthophoto and marked the cars with the name you wrote.
When I run the code I get an error.
I really like the templates for creating GUI scripts you have made, is it possible to create few more to show how to put items elsewhere in the GUI than the main menu?
I'd really like to add something to the right-click menu for a chunk, or to be able to add custom info to the chunk label (I need the total chunk error displayed on the main label, not in the reference panel).
A few basic examples or the API for adding things to different parts of the GUI would be great. Thanks!
If we have a project with multiple chunks and we set the script as "merge back" it will delete all chunks of the project, regardless they are the ones created for the split or not.
This can be even more problematic if we have set also the option "autosave" and the deletion of the rest of chuks can not be reversed.
This can be obviously a nasty surprise for some users with complex projects, as all chucks of the project will disappear except the one being processed.
Mi recommendation is warn about it in the script menu, or simply only delete the chuks created for the split process and not everything else.
Can someone help me in exporting clipped point cloud using python code in Metashape. I am using 1.6.4 version of Agisoft
Hi,
as the title says, how do I convert the depth map to height map?
I tried using altoff + depth, but it doesn't seem to be quite right./(ㄒoㄒ)/~~
Hi,
We have some scripts that use an older version of the Metashape API; some users are using newer versions of the API which causes the scripts to fail. We plan to update the scripts, but for ease we'd also just like to point users to the wheels of the versions we used.
I cannot find the URL containing the wheel for Windows and Linux version 1.8.4, nor can I find a page that easily provides links to all previous releases.
thanks
Hello,
I have the following error : AttributeError: module 'open3d' has no attribute 'registration' just after a clean install.
Has registration moved to open3d.pipelines ?
Thanks
I am using the Gaussian Splatting export script but it seems like all the point3d_id
's referenced in points3D.txt
do not exist in the IDs in images.txt
. However I am not familiar enough with the Metashape API to figure out what the issue is. I would continue to look into this but would appreciate any help in the meantime, thanks!
Attached are some sample reconstruction files demonstrating the issue; I have converted it to .txt format for easy reading.
images.txt
points3D.txt
Hi,
I am trying to use the automatic_masking
script, however while the installation procedure went smoothly when I tried to run the script on my images I got the following error message:
Error: module 'rembg.bg' has no attribute 'get_model'
Any idea how to resolve it?
I am getting the following error afterdefining the following.
In line doc = Metashape.document
AttributeError: module 'Metashape.Metashape' has no attribute 'document'
I am using the following code. Please let me know if I am missing something. Also, please correct other mistakes in the code if there are any.
import os
import Metashape
import numpy as np
pa='/home/nys09/'
pat='/home/nys09/Trial1Beamch_arc/'
b=[]
c=os.path.join(pa,"arc_imagelist_t1.txt")
images = open(c,"r+")
a = np.loadtxt(images,dtype=str)
for i in range(np.shape(a)[0]):
b.append(pat+str(a[i]))
doc = Metashape.document
chunk = doc.addChunk()
chunk.addPhotos(b)
camera = chunk.cameras[0]
camera.photo.meta["Exif/FocalLength"]
chunk.matchPhotos(accuracy=Metashape.HighAccuracy, generic_preselection=True,reference_preselection=False)
chunk.alignCameras()
doc.save(path = "project.psz", chunks = [doc.chunk])
Hi,
While having the cameras.json
file in 3D gaussian splatting does not seem to be an important requirement for visualizing the scenes, some visualizers do look for the cameras.json file (e.g. NeRFStudio's port https://github.com/yzslab/nerfstudio/tree/gaussian_splatting). It might be useful to export this file too.
(lines https://github.com/agisoft-llc/metashape-scripts/blob/master/src/export_for_gaussian_splatting.py#L332)
I'm trying to create a set of scripts, with one "metashape_util.py" script which is loaded in each of my individual scripts so that I don't have to rewrite much of the code
One big issue I am running into now is that if for example "toolset1.py" has the following code:
import metashape_util
and "metashape_util.py" has the following code:
found_major_version = ".".join(Metashape.app.version.split('.')[:2])
Then when I load "metashape_util.py" with the load script button in the console GUI, I get this error:
2020-03-19 21:44:57 Traceback (most recent call last):
2020-03-19 21:44:57 File "[...]/src/metashape_gliht_tools.py", line 20, in
2020-03-19 21:44:57 import metashape_util as mu
2020-03-19 21:44:57 File "[...]/src/metashape_util.py", line 8, in
2020-03-19 21:44:57 found_major_version = ".".join(Metashape.app.version.split('.')[:2]) #1.5 or 1.6
2020-03-19 21:44:57 NameError: name 'Metashape' is not defined
2020-03-19 21:44:57 Error: name 'Metashape' is not defined
Is there any suggested work around for this?
Every example that calls Metashape.app.document fails because Metashape.app.document
returns NoneType
. Expect examples to work as listed in the documentation:
import Metashape
chunk = Metashape.app.document.addChunk()
chunk.addPhotos(["IMG_0001.jpg", "IMG_0002.jpg"])
camera = chunk.cameras[0]
camera.photo.meta["Exif/FocalLength"]
Traceback (most recent call last):
File "<ipython-input-34-087caf902849>", line 2, in <module>
chunk = Metashape.app.document.addChunk()
AttributeError: 'NoneType' object has no attribute 'addChunk'
System specs:
Hello,
Request regarding gaussian splatting export python script
as a pinhole model, would it be possible to handle fisheye and frame and handle cam groups as well during the export ?
here with 2 fisheye cameras
each has a fisheye model like that
when executing export gaussian splatting
results are like that (note the size of images.bin)
the script returns that error handled
2023-11-21 19:39:09 Camera 00457_AR (key = 3457) has unsupported sensor (key = 3)
2023-11-21 19:39:09 Camera 00458_AR (key = 3458) has unsupported sensor (key = 3)
2023-11-21 19:39:09 Camera 00459_AR (key = 3459) has unsupported sensor (key = 3)
2023-11-21 19:39:09 Camera 00460_AR (key = 3460) has unsupported sensor (key = 3)
2023-11-21 19:39:09 Camera 00461_AR (key = 3461) has unsupported sensor (key = 3)
2023-11-21 19:39:09 Camera 00462_AR (key = 3462) has unsupported sensor (key = 3)
2023-11-21 19:39:09 Camera 00463_AR (key = 3463) has unsupported sensor (key = 3)
2023-11-21 19:39:09 Camera 00464_AR (key = 3464) has unsupported sensor (key = 3)
2023-11-21 19:39:09 Camera 00465_AR (key = 3465) has unsupported sensor (key = 3)
2023-11-21 19:39:09 Camera 00466_AR (key = 3466) has unsupported sensor (key = 3)
2023-11-21 19:39:09 Camera 00467_AR (key = 3467) has unsupported sensor (key = 3)
2023-11-21 19:39:09 Camera 00468_AR (key = 3468) has unsupported sensor (key = 3)
2023-11-21 19:39:09 Camera 00469_AR (key = 3469) has unsupported sensor (key = 3)
2023-11-21 19:39:09 Camera 00470_AR (key = 3470) has unsupported sensor (key = 3)
2023-11-21 19:39:09 Camera 00471_AR (key = 3471) has unsupported sensor (key = 3)
2023-11-21 19:39:09 Camera 00472_AR (key = 3472) has unsupported sensor (key = 3)
2023-11-21 19:39:09 Camera 00473_AR (key = 3473) has unsupported sensor (key = 3)
2023-11-21 19:39:09 Camera 00474_AR (key = 3474) has unsupported sensor (key = 3)
2023-11-21 19:39:09 Camera 00475_AR (key = 3475) has unsupported sensor (key = 3)
2023-11-21 19:39:09 Camera 00476_AR (key = 3476) has unsupported sensor (key = 3)
2023-11-21 19:39:09 Camera 00477_AR (key = 3477) has unsupported sensor (key = 3)
2023-11-21 19:39:09 Camera 00478_AR (key = 3478) has unsupported sensor (key = 3)
2023-11-21 19:39:09 Camera 00479_AR (key = 3479) has unsupported sensor (key = 3)
2023-11-21 19:39:09 Camera 00480_AR (key = 3480) has unsupported sensor (key = 3)
2023-11-21 19:39:09 Camera 00481_AR (key = 3481) has unsupported sensor (key = 3)
2023-11-21 19:39:10 Found 0 cropped projections
2023-11-21 19:39:10 Saved 0 calibrations
2023-11-21 19:39:10 Saved 0 cameras
2023-11-21 19:39:12 Saved 408837 points from 408837 tracks
2023-11-21 19:39:12
2023-11-21 19:39:12 Done
2023-11-21 19:39:12 -----------------------------------
Hello,
I want to create a small script to export estimated coordinates from a multi-frame chunk using the function saveReference. So I created a loop as you can see in the following script. The problem is I only obtain the coordinates of the active frame. It create the right number of file but they all have the same coordinates of the frame that is open in Metashape.
I can find anything about that problem so I'll be glad if someone as an idea about this issue.
import Metashape as ms
import os
doc = ms.app.document
path="suivi_reperes/"
i=0
for frame in doc.chunks[5].frames: #I'm only interested in this chunk number 5
file_name=path+'reperes_t'+str(i) frame.saveReference(file_name,PhotoScan.ReferenceFormatCSV,items=PhotoScan.ReferenceItemsMarkers,columns="n,[u|v|w],")
i+=1
I have a script that worked for an older version but doesn't on new versions. Is there a simple way to update it to work or are the changes to the python api to much?
The colmap created by the Gaussian splatting can be used by img2poses.py in https://github.com/Totoro97/NeuS/tree/main/preprocess_custom_data. However, in most cases it will cause "Don't need to run COLMAP
Post-colmap
Cameras 5
Images # 35
Traceback (most recent call last):
File "E:\dataprep\imgs2poses.py", line 17, in
gen_poses(args.scenedir, args.match_type)
File "E:\dataprep\pose_utils.py", line 264, in gen_poses
save_poses(basedir, poses, pts3d, perm)
File "E:\dataprep\pose_utils.py", line 67, in save_poses
cams[ind-1] = 1
IndexError: list assignment index out of range" Or
"Don't need to run COLMAP
Post-colmap
Cameras 5
Images # 55
ERROR: the correct camera poses for current points cannot be accessed
Done with imgs2poses". This means that the output is different from standard colmap output.
I have a project using WGS / UTM zone 32618 when I export.
the gaussian splatting is jumping all over the place and then settles. This is due to the coordinate system and being very far away from 0,0,0.
I tried changing the coordinate system to local coordinates but the gaussian is just a blurry mess.
I use Metashape Pro for processing large aerial data which takes days to complete in some cases. Power supply is an issue and when there is a power cut, i lose many hours (days) of work since the script does not continue from where it was interrupted.
I used the code below to export model:
doc = Metashape.Document()
chunk = doc.addChunk()
chunk.addPhotos(photos)
chunk.matchPhotos(keypoint_limit=40000, tiepoint_limit=10000, generic_preselection=True, reference_preselection=True)
chunk.alignCameras()
chunk.optimizeCameras()
chunk.buildDepthMaps(downscale=2, filter_mode=Metashape.MildFiltering)
chunk.buildModel(source_data=Metashape.DepthMapsData)
chunk.buildUV(page_count=2, texture_size=4096)
chunk.buildTexture(texture_size=4096, ghosting_filter=True)
has_transform = chunk.transform.scale and chunk.transform.rotation and chunk.transform.translation
if has_transform:
chunk.buildDenseCloud()
chunk.buildDem(source_data=Metashape.PointCloudData)
chunk.buildOrthomosaic(surface_data=Metashape.ElevationData)
chunk.exportModel(output_folder + "/model.obj", texture_format=Metashape.ImageFormat.ImageFormatPNG)
chunk.exportCameras(output_folder + "/cameras.xml")
t1 = time.time()
print("Processing finished, results saved to " + output_folder + ".", t1 - t0)
but the texture is not right:
can you help me with this problem? @Jean-Roc @VladimirPobedinskiy @PolarNick239 @Vineg @matjash
The script seems to work in the way that we select and open a chunk. Now If we use the script it will copy the bounding box of any other existing Chunk in the project.
The only way it works OK is if the project only has two Chunks, the origin and a compatible destiny.
If the project has any other unrelated Chunk it generates multiple problems:
My suggestion is:
Hi, here is a script named as "footprints_to_shapes.py". It given footprint of camera opened in chunk.
Is there a way that this script, can provides the precise footprint boundary of the raster in Ortho tab using DEM or OrthoMosaic generated i.e. See below image as example _Footprint to Raster
I have Metashape Pro 1.5.1 and recently loaded the image footprints script. The menu shows up fine, and when the script runs a footprints group gets created in the left menu, but it's empty and exporting leads to an empty shapefile. Is there any customization to the script that is necessary, and do all images have to be aligned with a mesh and point cloud for this script to do its job properly? Thank you for the development efforts
Is there a script to merge camera calibration groups by lens type?
I understand that the camera calibration groups cameras by camera serial name.
To merge by lens it is a very slow and manual process to select all cameras with the same lens and merge groups.
Does a script exist to do this?
I'd like to express my gratitude for the superb conversion scripts you've provided (export_for_gaussian_splatting.py). The rendering results I've achieved using Metashape significantly outperform those from COLMAP.
Nevertheless, I've encountered a couple of challenges:
Cropped/Unsupported Sensors: On certain occasions, I've noticed "cropped/unsupported sensors" messages, even when Metashape successfully aligns all the images.
Incorrect Projection Values: I've debugged the scripts and printed the "unproject" and "project" values for the "right, left, top, and bottom" parameters. Some inconsistencies have been observed. For instance, the left value is greater than the right, and there are extremely large negative values post-projection.
Given these issues, I have a few questions:
Why might these anomalies be occurring?
Is there a recommended approach to rectify them?
If opting for undistortion leads to fewer views, does the script offer an option to bypass the undistortion step?
I'd appreciate any insights or guidance you can provide on this matter. Thank you in advance!
Hello there,
I am a newbie to using scripts,
I have 1250 photos to proecess and to prepare DEM and Orthophoto however since my hardware limits me up I wanted to split my work into chunks to work fluently without any crashes
I aligned all the photos firstly and then I used the script split in chunks however split in chunks command only does duplicate my dataset but nothing all
I am using Agisoft Metashape 1.8
Any help would be appreciated .
In lines 78 to 80 of above mentioned script, there is a call to Metashape.utils.dmat2euler which does not exist...
we get following error when running:
Error: 'Metashape.Utils' object has no attribute 'dmat2euler
Hola, he intentado usar el script footprints_to_shapes.py con buenos resultados con pocas fotos, pero cuando intento hacerlo en un proyecto con 15000 imágenes el programa no responde y se cuelga.
I can't load split_in_chunks_dialog.py on one of my installs of Metashape.
2020-01-28 11:22:09 from PySide2 import QtGui, QtCore, QtWidgets
2020-01-28 11:22:09 ImportError: No module named 'PySide2'
2020-01-28 11:22:09 Error: No module named 'PySide2'
It seems the python install doesn't have PySide2 library available, but where should it be installed?
This is if I load the script in via the Console in Metashape 1.5.1
I'm testing the automatic_masking script and rembg with different models
https://github.com/agisoft-llc/metashape-scripts/blob/master/src/automatic_masking.py
In the rembg code this command changes the model
rembg i -m isnet-general-use path/to/input.png path/to/output.png
Is it possible to change the model used the isnet-general-use
?
The result of this script is always a messed bounding box. This can be currently solved with the script included in the package where we can copy back the old bounding box from the original model.
It would be nicer and more elegant if this could be done automatically after merged the pieces. Having said that there is a clear workaround as explained.
hello,I want to use python scripts in photoscan, but I met some problems, could I get some help?
you use it in release 1.4, so could I use in Release 1.2, or should I update my photoscan?
then, how to use these scripts? when i use the tools->run scripts, nothing happened.
thanks for your reply.
I tried running this script in Metashape 1.5.1, but it seems to just duplicate my chunk (I set a 2 x 2 split as test), with all photos in each one.
I'm looking through the code and can't figure out at what point it actually does any splitting. I see it is recalculating the region, but it seems to have no effect?
Is there a way to remove existing menu items? While debugging it gets messy if I keep uploading them several times.
Ideally just hold on to a reference for the newly added item and delete it with QtWidgets would work? Not sure how to find that though for an item I've added.
Hi,
The line code "depth = chunk.depth_maps[camera].image()" gets the depth map level 1. How can I get all depth map levels?
Thank you in advance :)
Hello @PolarNick239
would it be possible to skip broken image path in PSX when using that export gaussian splatting script ?
something like that ?
Here frame.photo.path is not working but this is the idea.
either with a dedicated function or with a modification like that.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.