Agisoft Metashape

Agisoft Metashape => Python and Java API => Topic started by: Foxy on November 17, 2020, 07:20:25 PM

Title: Import Reference for Markers Local Coordinate System
Post by: Foxy on November 17, 2020, 07:20:25 PM
Hello,

I've been trying to import a reference for markers in a local CS. I don't get an error message, nonetheless it will not asign the coordinates to the markers and the corresponding boxes remain empty in the referemce pane. So how can I import local coordinates for markers? Here is the code:

import os
import Metashape

doc     = Metashape.app.document
chunk   = doc.chunk
#chunk.label = "V1"

### Create project file
##project_path = 'D:/Franziska/py_test.psx'
##doc.save(project_path)
###doc.open(project_path)

# Add Photos
path_photos = "D:/Python/C_dreieckPfeiler_V1_Comprimiert/Bilder/"
image_list  = os.listdir(path_photos)
photo_list   = list()
for photo in image_list:
   if photo.rsplit(".",1)[1].lower() in  ["jpg", "jpeg", "tif", "tiff"]: photo_list.append("/".join([path_photos, photo]))
chunk.addPhotos(photo_list, strip_extensions = False)

chunk.crs = Metashape.CoordinateSystem('LOCAL_CS["Local CS",LOCAL_DATUM["Local Datum",0],UNIT["metre",1]]') # define crs as local coordinate system

#Align Photos
chunk.matchPhotos(downscale=1, generic_preselection=True, reference_preselection=False)
#Downscale=1 means high accuracy
chunk.alignCameras()

##Detect markers
marker = chunk.detectMarkers(Metashape.TargetType.CircularTarget12bit, 50)

path = 'D:/Python/C_dreieckPfeiler_V1_Comprimiert/KoordinatenMarker2.txt'
##KOS = open(path,"r")
##print(KOS.read())

chunk.marker_crs = Metashape.CoordinateSystem('LOCAL_CS["Local CS",LOCAL_DATUM["Local Datum",0],UNIT["metre",1]]') # define crs as local coordinate system
#chunk.crs = Metashape.CoordinateSystem("EPSG::9001") # define crs as local coordinate system

#crs = Metashape.CoordinateSystem()
#crs.init('LOCAL_CS["Local CS",LOCAL_DATUM["Local Datum",0],UNIT["metre",1]]')
#chunk.importReference(path,format=Metashape.ReferenceFormatCSV, columns = "nxyz", delimiter =" ",skip_rows=1,items = Metashape.ReferenceItemsMarkers,ignore_labels=True,threshold=0.1)
chunk.importReference(path,format=Metashape.ReferenceFormatCSV, columns = "nxyz", delimiter =" ",items = Metashape.ReferenceItemsMarkers,crs = Metashape.CoordinateSystem('LOCAL_CS["Local CS",LOCAL_DATUM["Local Datum",0],UNIT["metre",1]]'))
chunk.updateTransform()

Thank You!!
Title: Re: Import Reference for Markers Local Coordinate System
Post by: Alexey Pasumansky on November 21, 2020, 12:18:47 PM
Hello Foxy,

Can you please provide a few starting lines from the file that you are trying to import and a screenshot of the Reference pane with the marker labels (or at least the names of the detected markers in this project)?
Title: Re: Import Reference for Markers Local Coordinate System
Post by: Foxy on November 24, 2020, 12:41:43 PM
Hello Alexey,

this is what I'm trying to import:

target1   -0.003 0 0.175
target2   -0.003 0 0.083
target3   0.3990 0 0.083
target4   0.8000 0 0.083
target5   1.2990 0 0.083
target6   1.2990 0 0.178
target7   1.7000 0 0.083
target8   2.0880 0 0.083
target9   2.0880 0 0.177

and I've attached a screenshot of my reference pane.

Thank you!
Title: Re: Import Reference for Markers Local Coordinate System
Post by: Alexey Pasumansky on November 24, 2020, 03:58:10 PM
Hello Foxy,

It seems that the labels in the text file do not correspond to the marker labels in the project.
The marker labels in the chunk have "space" symbol between the "target" word and it's number.

So you either should modify the labels in the file being imported, and therefore change the delimiter as well. Or change the marker labels in the chunk:
Code: [Select]
for marker in chunk.markers:
    marker.label = marker.label.replace(" ", "")
Title: Re: Import Reference for Markers Local Coordinate System
Post by: Foxy on November 24, 2020, 05:37:57 PM
Hello,

so changing that didn't solve the problem but chaning the delimeter from 'space' to comma did. I'm not sure why though.

Thanks !