Forum

Author Topic: Import .csv marker file  (Read 7581 times)

claytonb8298

  • Newbie
  • *
  • Posts: 13
    • View Profile
Import .csv marker file
« on: January 12, 2023, 12:14:21 AM »
Hello,

I am looking for a way to import a simple marker file that has the following characteristics.

GCP, Image_name, x pixel, y pixel
GCP, Image_name, x pixel, y pixel
GCP, Image_name, x pixel, y pixel
GCP, Image_name, x pixel, y pixel
etc.

We have moved to Agisoft Metashape from Pix4d and have many projects that have been completed in Pix4d that we may need to revisit using Metashape.  But to have to revisit and recontrol the project in Metashape is not something we would want to do.

Pix4d has two export options for markers, one is a simple .csv file like that above, and the other is a Pix4d .xml file.

Metashape allows for a marker input by Metashape .xml, not at all by .csv.  The really confusing thing is it seems like the .xml version should be attempting a universal export that most softwares could understand.

I have found scripts for exporting a .csv formatted marker file like that above, but not for importing something similar.

Any help is appreciated.

Clayton

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15407
    • View Profile
Re: Import .csv marker file
« Reply #1 on: January 12, 2023, 06:17:03 PM »
Hello Clayton,

We have a script prototype similar to your needs. Can you please check, if it works on your project?

In case there are any errors or problems, please provide the output from the Console pane after executing the script.

Code: [Select]

#markers batch import script
##data format:
#image_name, gcp_name, px_x, px_y
##sample data:
#DJI_0470.JPG,GCP_1,2664,3207
#

import Metashape, os

def import_markers_csv():

doc = Metashape.app.document
if not (len(doc.chunks)):
print("No chunks. Script aborted.\n")
return False

path = Metashape.app.getOpenFileName("Select markers import file:")
if path == "":
print("Incorrect path. Script aborted.\n")
return False
print("Markers import started.\n")  #informational message
file = open(path, "rt") #input file

eof = False
#line = file.readline() #skipping header line
line = file.readline()
if not len(line):
eof = True

chunk = doc.chunk

while not eof:
sp_line = line.strip().rsplit(",", 3)   #splitting read line
y = float(sp_line[3]) #x- coordinate of the current projection in pixels
x = float(sp_line[2]) #y- coordinate of the current projection in pixels
label = sp_line[0] #image file name
marker_name = sp_line[1] #marker label

flag = 0
for camera in chunk.cameras:

if os.path.basename(camera.photo.path).lower() == label.lower(): #searching for the camera

for marker in chunk.markers: #searching for the marker (comparing with all the marker labels in chunk)
if marker.label.lower() == marker_name.lower():
marker.projections[camera] =  Metashape.Marker.Projection(Metashape.Vector([x,y]), True) #setting up marker projection of the correct photo)
flag = 1
break

if not flag:   #creating new marker instance
marker = chunk.addMarker() 
marker.label = marker_name
marker.projections[camera] =  Metashape.Marker.Projection(Metashape.Vector([x,y]), True)

break

line = file.readline() #reading the line from input file
if not len(line):
eof = True
break # EOF

#chunk.crs = Metashape.CoordinateSystem("EPSG::4326")
file.close()
print ("Markers import finished.\n")
return True

Metashape.app.addMenuItem("Custom menu/Import markers from CSV file", import_markers_csv)
Best regards,
Alexey Pasumansky,
Agisoft LLC

claytonb8298

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Import .csv marker file
« Reply #2 on: March 01, 2024, 12:30:13 AM »
Hi Alexy,

I am testing this now.  Over a year later.  For some reason I am not reliably tracking items I post.

I tested it, and I can't get the script to request a file attachment to load for the marker assignments.  I will continue to review, but I am not sure what I am doing wrong yet.

claytonb8298

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Import .csv marker file
« Reply #3 on: March 01, 2024, 01:06:47 AM »
@Alexey

Hi, I figured out what I wasn't aware of.  Running this script creates a custom menu pull down.  I found that and ran the custom menu and get an error.

Error: list index out of range

I will continue to explore.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15407
    • View Profile
Re: Import .csv marker file
« Reply #4 on: March 01, 2024, 03:13:19 PM »
Hello Clayton,

Can you share the CSV file that you are using? If possible, please send the text file and a project in PSZ format to support@agisoft.com with cameras added to the Workspace pane (no processing applied), that we can use to investigate the problem .
Best regards,
Alexey Pasumansky,
Agisoft LLC

dpitman

  • Sr. Member
  • ****
  • Posts: 256
    • View Profile
Re: Import .csv marker file
« Reply #5 on: March 02, 2024, 11:40:57 PM »


Metashape allows for a marker input by Metashape .xml, not at all by .csv.  The really confusing thing is it seems like the .xml version should be attempting a universal export that most softwares could understand.


Hi Clayton.

Metashape can import .csv perfectly well without any scripting.  I am not sure why it does not work for you?


Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15407
    • View Profile
Re: Import .csv marker file
« Reply #6 on: March 06, 2024, 06:28:50 PM »
Hello dpitman,

The request is quite different from the Import CSV functionality, Clayton requires to import markers' projections (2D coordinates in pixels on the images) rather then XYZ coordinates in the global coordinate system.
Best regards,
Alexey Pasumansky,
Agisoft LLC

dpitman

  • Sr. Member
  • ****
  • Posts: 256
    • View Profile
Re: Import .csv marker file
« Reply #7 on: March 07, 2024, 04:31:41 AM »
Hello dpitman,

The request is quite different from the Import CSV functionality, Clayton requires to import markers' projections (2D coordinates in pixels on the images) rather then XYZ coordinates in the global coordinate system.

Ah, my mistake.  Sorry for the interruption.  Would the purpose be to try and eliminate the step in MS of adjusting the marker coordinate to the target in the image?  If so, that would not cause any reduced ability for MS to optimize cameras? The image pixel value would produce the same result as the manual point adjustment procedure?

Thank you!