Forum

Author Topic: Export markers  (Read 18483 times)

erix

  • Newbie
  • *
  • Posts: 8
    • View Profile
Export markers
« on: April 11, 2013, 12:13:55 PM »
Could someone give me a hint on how to export markers with python?
I find the python api somewhat confusing.

I want to get the xyz coordinates from the projected markers in 3D. Not the 2D coordinates in pixels.
Is this possible?

In this topic Alexey mentioned it should be possible.
http://www.agisoft.ru/forum/index.php?topic=492.msg2153#msg2153
« Last Edit: April 11, 2013, 12:21:32 PM by erix »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Export markers
« Reply #1 on: April 11, 2013, 12:43:59 PM »
Hello erix,

Do you need to save source or estimated marker coordinates?
Best regards,
Alexey Pasumansky,
Agisoft LLC

erix

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Export markers
« Reply #2 on: April 11, 2013, 01:07:13 PM »
I guess its the estimated  marker coordinates.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Export markers
« Reply #3 on: April 11, 2013, 01:43:04 PM »
Hello erix,

I think that this sample script will give you estimated coordinates for the first marker in the Workspace, providing that chunk coordinate system is defined (not Local coordinates).
The result is a vector.

Code: [Select]
doc = PhotoScan.app.document
chunk = doc.activeChunk

m = chunk.markers[0]
v = m.position
v.size = 4
v.w = 1

T = chunk.transform
v_t = T * v
v_t.size = 3

proj = chunk.crs

v_out = proj.project(v_t)

Please let me know if it works correctly.
Best regards,
Alexey Pasumansky,
Agisoft LLC

erix

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Export markers
« Reply #4 on: April 11, 2013, 02:24:10 PM »
Thanks for fast response.

I get "TypeError: unsupported types" in line:
v_t = T * v

any clue on why?

erix

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Export markers
« Reply #5 on: April 11, 2013, 02:30:43 PM »
T = chunk.transform
str(type(T))

generates <class 'NoneType'>
Why does chunk.transform return null?

« Last Edit: April 11, 2013, 02:35:34 PM by erix »

erix

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Export markers
« Reply #6 on: April 11, 2013, 04:46:38 PM »
Anyone got this script working? Or do you experience same result?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Export markers
« Reply #7 on: April 11, 2013, 05:45:53 PM »
Hello erix,

"chunk.transform" may be Null is case the chunk is not referenced?

Is it so in your project? In this case you can assing to chunk.transform diagonal identity matrix and reuse the script.
Best regards,
Alexey Pasumansky,
Agisoft LLC

erix

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Export markers
« Reply #8 on: April 11, 2013, 05:52:09 PM »
I'm not sure I understand.
How do I assign a diagonal identiry matrix to chunk.transform?
chunk.transform = PhotoScan.Matrix.diag( (1,2,3,4) ) ?
or
chunk.transform = PhotoScan.Matrix.diag( (1,1,1,1) ) ?
« Last Edit: April 11, 2013, 05:59:51 PM by erix »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Export markers
« Reply #9 on: April 11, 2013, 06:12:22 PM »
Hello erix,

The second variant is correct:
chunk.transform = PhotoScan.Matrix.diag( (1,1,1,1) )
Best regards,
Alexey Pasumansky,
Agisoft LLC

jedfrechette

  • Full Member
  • ***
  • Posts: 130
  • Lidar Guys
    • View Profile
    • www.lidarguys.com
Re: Export markers
« Reply #10 on: April 11, 2013, 06:57:09 PM »
It would be nice to have the transform default to the identity matrix instead of None.
Jed

erix

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Export markers
« Reply #11 on: April 12, 2013, 11:43:50 AM »
I still don't managed to get a desirable result.
I want to export some marker to my 3D program of choice, and have the marker lined up with the exported model as OBJ.
The coordinates I get from the script above is not near the point on the exported 3D model.
Any hints or input?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Export markers
« Reply #12 on: April 12, 2013, 11:53:55 AM »
Hello erix,

Could you please send us the project file with the markers (3d-model and depth maps could be removed) on support@agisoft.ru, so we could get the script working?
Best regards,
Alexey Pasumansky,
Agisoft LLC

erix

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Export markers
« Reply #13 on: April 12, 2013, 01:16:52 PM »
It seems that it wasn't anything wrong with the outputed marker positions.
The problem occured during import to the engine. Thank you for all your help.

Here's the code I use to write a csv of marker.


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()


Merzel

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Export markers
« Reply #14 on: January 04, 2017, 06:46:50 PM »
hey erix,
I tried the same code as you posted last, but I got the same typeerror es you earlier. what did you do about it? Is there an easier way to export my markers together with my mesh?
thanks guys