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.

Messages - spatialdigger

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

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

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


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?


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

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

Python and Java API / Re: Export GCPS with error values
« on: August 25, 2021, 12:31:46 AM »
Is there any way to access the nxyzUVW values in python without exporting them?

Would it be something like:

Code: [Select]
n = Metashape.ReferenceItemsMarkers.n

Code: [Select]
n, x, y, z, U, V, W, = Metashape.ReferenceItemsMarkers

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?

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?

We have a slate with the project details, so obviously that wont align, and we wouldn't want it to, I've added a try/except clause in, but I welcome recommendations, incl. a way to avoid writing to csv and keep in pandas df

Python and Java API / Re: Define agisoft_LICENSE environment variable
« on: August 02, 2021, 05:34:14 PM »
Hi, we are on Windows 10.

We have several machines running the different versions of Metashape and I'm writing a script/helper program so before launching I want to check the license on the machine so I can grey out certain options to avoid the script crashing. So if they have the standard license then only certain parts of the code are avaiable to run.

In addition I've had to copy the license into the python project, I'd rather just point to the actual license file.


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.

ok this kind of does the job, I'd rather have it in a pandas data frame but I can read it in from the csv.

Code: [Select]
chunk.exportReference(path=archive_path + '\\cameras.csv',format=Metashape.ReferenceFormatCSV, items=Metashape.ReferenceItemsCameras, columns='nuvwdef', delimiter =',')

Thanks Paulo,

I'm trying to build it up bit by bit so I understand.

I can access the cameras via chunk.cameras

But when I run the following I get:
    TypeError: argument 1 must be Metashape.Metashape.Vector, not None

Code: [Select]
for camera in chunk.cameras:
    error = chunk.transform.matrix.mulp( -

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

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

    # detect markers
    # assign 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.buildModel(source_data=Metashape.DataSource.DenseCloudData, surface_type=Metashape.Arbitrary, interpolation=Metashape.EnabledInterpolation, face_count=Metashape.MediumFaceCount)
    chunk = doc.chunk
    espgCode = 27700
    localCRS = Metashape.CoordinateSystem("EPSG::" + str(espgCode))
    proj = Metashape.OrthoProjection() = 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)

Python and Java API / Re: launch Metashape gui from python
« on: July 28, 2021, 08:09:43 PM »
With more research I see that this will be better achieved outside of metashape and purely in python

Python and Java API / Re: Loading coordinates of reference markers
« on: July 28, 2021, 08:08:53 PM »

I think this is a GIS issue, the jpgs are displayed correctly, but require a spatial reference to be set in the GIS.

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]
    chunk = doc.chunk
    espgCode = 27700
    projectCRS = Metashape.CoordinateSystem("EPSG::" + str(espgCode))
    proj = Metashape.OrthoProjection() = 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)

Pages: [1] 2