Forum

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - spatialdigger

Pages: [1]
1
Python and Java API / Metashape API on standard license
« on: September 28, 2021, 05:14:07 PM »
Hi,

I have Metashape Pro on one machine and a Standard version on another.

On Pro I can use the api:
Code: [Select]
import Metashape
Metashape.license.valid

True

No problems.

In standard the same code returns false.

In pro I had to copy the .lic file to python's virtual environment but I cannot find a .lic in the standard version's directory
How do I get the API to recognise that the version is licenced albeit on a standard licence rather than pro?

Thanks

2
Python and Java API / Check if orthomosaic has been built?
« on: September 12, 2021, 04:29:19 AM »
I'm trying to check if the orthomosaic has been built or not.

chunk.orthomosaic returns an object because it is a method.

So I can't simply try:

ortho = chunk.orthomosaic
if ortho:
  print("ortho has been built")

as it will always return true because it references the method.

So how do I go about checking if the orthomosaic has been built?

Is it similar as the check for the alignment step?:

Code: [Select]

align = False
  for camera in chunk.cameras:
    if camera.transform:
      print("Found first aligned camera")
      align = True
      break

maybe something like:
Code: [Select]
for ortho in chunk.orthomosaic:
  if ortho.something:
    ortho_built = True

3
Python and Java API / Export GCPS with error values
« on: August 24, 2021, 12:57:13 PM »
Hi, I'm trying to export the Ground Control Points and the associated error - I'm wanting to assess the error in a script.

I've seen this, but it does not deport the error columns or the overall error
Code: [Select]
saveReference(path, format = PhotoScan.ReferenceFormatCSV, items = PhotoScan.ReferenceItemsCameras, delimiter = ",")
How is this achieved?

4
So, I can use importReference to get the coordinates from a csv file, however, I would rather bring it in directly from pandas without writing to csv first.

Here's my csv import code

Code: [Select]
chunk.importReference(path=TARGET_PATH, format=Metashape.ReferenceFormatCSV, columns='nxyz', delimiter=',', create_markers=True, skip_rows=1)
The pandas dataframe is a conventual one

Code: [Select]
  target_id     easting    northing  height
0  target 3  340065.045  158038.578  12.628
1  target 2  340065.429  158038.089  12.593
2  target 4  340066.198  158038.501  12.581
3  target 1  340065.495  158039.022  12.589

So how could I import this directly and skip the need to export to csv?

5
Python and Java API / Define agisoft_LICENSE environment variable
« on: July 31, 2021, 07:41:40 PM »
I have the pro version, and I'm connecting to the api from python externally from Metashape.

Everything works as expected, however I have to copy the license file to the python directory for it t register as a legitimate copy.

It would make life easier if I could tell python/Metashape where to look for the license file - rather than making a copy.


So far I've seen  agisoft_LICENSE environment variable mentioned but I do not understand how to initiate it in a python script.

Thank you for any help you can offer.

6
I have an external scripted workflow which does the usual processes (adds photos, aligns, import target coords, through to dense point cloud, code included for reference)

I would like to access the individual image/photo name and the calculated camera xyz location and any other directional information that exists so this can be brought into a pandas dataframe.

Any idea where to start?

Code: [Select]
    doc = Metashape.Document()

    # set up a chunk
    chunk = doc.addChunk()

    # add photos
    chunk.addPhotos(filenames=photo_list)

    print(str(len(photo_list)) + " Added")

    # detect markers
    chunk.detectMarkers()
    # assign crs
    chunk.crs = Metashape.CoordinateSystem("EPSG::27700")

    count_photos = len(image_list)

    # import target coords
    chunk.importReference(path=targets_path, format=Metashape.ReferenceFormatCSV,
                        columns='nxyz', delimiter=',',create_markers=True, skip_rows=1)

    chunk.matchPhotos(downscale=2, generic_preselection=True, reference_preselection=True, keypoint_limit=80000,
                      tiepoint_limit=3000)  # , filter_mask=False, mask_tiepoints=True, keypoint_limit=40000, tiepoint_limit=4000

    chunk.alignCameras(adaptive_fitting=True)
    chunk.buildDepthMaps(downscale=4)
    chunk.buildDenseCloud()
    chunk.buildModel(source_data=Metashape.DataSource.DenseCloudData, surface_type=Metashape.Arbitrary, interpolation=Metashape.EnabledInterpolation, face_count=Metashape.MediumFaceCount)
    doc.save(filepath)
    chunk = doc.chunk
    espgCode = 27700
    localCRS = Metashape.CoordinateSystem("EPSG::" + str(espgCode))
    proj = Metashape.OrthoProjection()
    proj.crs = localCRS
    chunk.buildOrthomosaic(surface_data=Metashape.DataSource.ModelData, blending_mode=Metashape.MosaicBlending, projection=proj)
    chunk.exportRaster(path=ortho_path, image_format=Metashape.ImageFormatJPEG, save_world=True, projection=proj)
    docu_path = os.path.join(docu_path, "report.pdf")
    chunk.exportReport(path=docu_path, title=job + selected_job)
    doc.save(filepath)

7
I'm trying to assign a projection to build the orthomosaic and then export the orthomosaic as a GIS raster, currently the projection is not being picked up by the GIS.
Where am I going wrong?

Code: [Select]
    doc.save(filepath)
    chunk = doc.chunk
    espgCode = 27700
    projectCRS = Metashape.CoordinateSystem("EPSG::" + str(espgCode))
    proj = Metashape.OrthoProjection()
    proj.crs = projectCRS

    chunk.buildOrthomosaic(surface_data=Metashape.DataSource.ModelData, blending_mode=Metashape.MosaicBlending, projection=proj)

    chunk.exportRaster(path=ortho_path, image_format=Metashape.ImageFormatJPEG, save_world=True, projection=proj)

8
Python and Java API / launch Metashape gui from python
« on: July 28, 2021, 03:00:05 AM »
I know you can open a Metashape document into python: doc.open(filepath, read_only=False)

What  I would like to do is launch the program from within python so the user can troubleshoot any identified issues, caught in the script.

For instance if there is an exception the Metashape doc is opened in Metashape for the user to look and apply a manual fix.

I have Metashape pro.

9
Python and Java API / Loading coordinates of reference markers
« on: July 28, 2021, 02:48:12 AM »
I have

Code: [Select]
    doc = Metashape.Document()

    # set up a chunk
    chunk = doc.addChunk()

    # add photos
    chunk.addPhotos(filenames=photo_list)
    # doc.save(filepath)

    # detect markers
    chunk.detectMarkers()
    # assign crs
    chunk.crs = Metashape.CoordinateSystem("EPSG::27700")

All that works fine, I have a targets.csv file, setup as standard, works manually.

So I try the following:
   
Code: [Select]
chunk.loadReference(path=targets_path, format=Metashape.ReferenceFormatCSV, columns='nxyz', delimiter=',',create_markers=True)
And I get the following error, where am I going wrong?
Code: [Select]
Traceback (most recent call last):
  File "<input>", line 1, in <module>
AttributeError: 'Metashape.Metashape.Chunk' object has no attribute 'loadReference'

Pages: [1]