Forum

Author Topic: How can I write python scrip to input coordinate of the marker the same as GUI?  (Read 1188 times)

lyhour

  • Newbie
  • *
  • Posts: 41
    • View Profile
Excuse me everyone. I want to write python script to input coordinate x,y,z into the maker as in the figure attachment. I will show you my code that I have been achieve (not fully 100%). Noted that the marker in the figure is just example detection from the chessboard. The main purpose is I want to know the script how to input coordinate.
Code: [Select]
import Metashape
import textwrap
import glob
import os
global doc

doc = Metashape.app.document
print("Script started")

#creating new chunk
doc.addChunk()
chunk = doc.chunk
chunk.label = "New Chunk"

Metashape.app.gpu_mask = 2 ** len(Metashape.app.enumGPUDevices()) - 1
if Metashape.app.gpu_mask:
    print("the GPU is using")
    Metashape.app.cpu_enable = False

photo_list = list()
image_dir='GCPcode'
path_img = os.path.join(os.getcwd(),image_dir)
for j,img_file in enumerate(glob.glob(path_img+'/*.jpg')):
img_name = os.path.splitext(os.path.basename(img_file))[0]
photo_list.append(img_file)

chunk.addPhotos(photo_list)
keypoints = 40000 #align photos key point limit
tiepoints = 4000
chunk.matchPhotos(downscale=1, generic_preselection=True, filter_mask = False, keypoint_limit = keypoints, tiepoint_limit = tiepoints)
chunk.alignCameras()
print("\n************ start detect marker ***************\n")
chunk.detectMarkers(target_type=Metashape.CrossTarget, tolerance=30, filter_mask=False, maximum_residual=50)
cam = chunk.cameras[1]
# print the coordinate
for marker in chunk.markers:
x,y = marker.projections[cam].coord
m,n = cam.project(marker.position)
print(marker.label, x, y, m,n)
marker_coord = chunk.crs.project(chunk.transform.matrix.mulp(marker.position))
print("---- marker 3d coord:", marker_coord)
#------- script for input coordinate ---------
# I want to know how to do here

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Hello lyhour,

If you have the coordinate data in the external file, you should call chunk.importReference() command.

You can also use ignore_labels=True argument for this call, in this case the labels will be automatically re-assigned, based on the information in the input text file(label, X-coord, Y-coord, Z-coord), like you have requested in another thread:
Code: [Select]
#N,X,Y,Z
1,0.0,10.0,0.0
2,0.0,20.0,0.0
....
10.10.0,10.0,0.0
But since there's some symmetry in the marker distribution, the corner, from which the naming will be started, may be random.
Best regards,
Alexey Pasumansky,
Agisoft LLC

lyhour

  • Newbie
  • *
  • Posts: 41
    • View Profile
Dear Alex,

Thank you very much for you kind response. Please apology me for the late response due to notification is in the junk mail I didn't notice. I can solve it thank you very much.

Best Regards,

LYHOUR