Agisoft Metashape

Agisoft Metashape => Python and Java API => Topic started by: latexx on July 29, 2015, 01:30:19 PM

Title: Export xyz coordinates of Markers (version 1.1.6)
Post by: latexx on July 29, 2015, 01:30:19 PM
I was looking for how to get the xyz coordinates of markers. I guess there is only one way to get them, a script. So, I try to update this script to version 1.1.6 but I can't do it (I don't know a lot about phyton ...).

http://www.agisoft.com/forum/index.php?topic=1157.0

Code: [Select]
# exports all markers in activeChunk to csv.
# compatibility: Agisoft PhotoScan Professional 0.9.0
import PhotoScan
import math


FILEPATH = 'C:/marker_export.txt'

app = PhotoScan.app
doc = PhotoScan.app.document
chunk = doc.activeChunk
f = open(FILEPATH, 'w')
for item in chunk.markers:
if item.position == None:
continue
v = item.position
v.size = 4
v.w = 1
if not chunk.transform:
chunk.transform = PhotoScan.Matrix.diag( (1,1,1,1) )
T = chunk.transform
v_t = T * v
v_t.size = 3
proj = chunk.crs
v_out = proj.project(v_t)
f.write(item.label + ',' + str(v_out[0]) + ',' + str(v_out[1]) + ',' + str(v_out[2]) + '\n')
f.close()

So, can someone help me or give some orientations?

Thank you!!
Title: Re: Export xyz coordinates of Markers (version 1.1.6)
Post by: Alexey Pasumansky on July 29, 2015, 01:43:06 PM
Hello latexx,

doc.activeChunk -> doc.chunk
chunk.transform -> chunk.transform.matrix
Title: Re: Export xyz coordinates of Markers (version 1.1.6)
Post by: latexx on July 29, 2015, 01:48:23 PM
Thanks a lot for your reply!!!  :D :D

I changed it and now I have other problem:

Traceback (most recent call last):
  File "C:/******/python.py", line 22, in <module>
    v_t = T * v
TypeError: unsupported types

Could you say me something about this??

Again, thanks!!
Title: Re: Export xyz coordinates of Markers (version 1.1.6)
Post by: latexx on July 29, 2015, 01:52:42 PM
Sorry!! The problem is:

Traceback (most recent call last):
  File "C:/******/python.py", line 25, in <module>
    v_out = proj.project(v_t)
AttributeError: 'NoneType' object has no attribute 'project'
Title: Re: Export xyz coordinates of Markers (version 1.1.6)
Post by: Alexey Pasumansky on July 29, 2015, 02:00:23 PM
Hello latexx,

the error indicates that no geographic coordinate system is defined for the chunk.

You can try the following script where the additional check is implemented:
Code: [Select]
import PhotoScan


FILEPATH = 'C:/marker_export.txt'

app = PhotoScan.app
doc = PhotoScan.app.document
chunk = doc.chunk
f = open(FILEPATH, 'w')
for marker in chunk.markers:
if marker.position == None:
continue
T = chunk.transform.matrix
v_t = T.mulp(marker.position)
if chunk.crs:
v_out = chunk.crs.project(v_t)
else:
v_out = v_t
f.write(item.label + ',' + str(v_out[0]) + ',' + str(v_out[1]) + ',' + str(v_out[2]) + '\n')
f.close()
Title: Re: Export xyz coordinates of Markers (version 1.1.6)
Post by: latexx on July 29, 2015, 02:14:46 PM
It works!!! Thank you a lot!!!  :D :D :D :D