Forum

Author Topic: Marker tracking  (Read 10198 times)

lmg

  • Newbie
  • *
  • Posts: 30
    • View Profile
Marker tracking
« on: January 30, 2014, 04:12:39 PM »
I have done  the marker tracking in a multiframe 4D project, but in the Ground Control pane I am not able to visualize the coordinates and the scale bars for each frame: only the first frame values are visible. Please, I wish to visualize and to export the coordinates and the measures for each frame. How to do this?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15354
    • View Profile
Re: Marker tracking
« Reply #1 on: January 30, 2014, 04:35:36 PM »
Hello lmg,

Actually, checked markers should remain static across the whole frame sequence, as PhotoScan uses all checked markers in all the frames to reference the model.

And currently it is not possible to extract estimated marker coordinates from multi-frame chunks from GUI, but a Python script can help. Something like that for simple console output:
Code: [Select]
import PhotoScan

doc = PhotoScan.app.document
chunk = doc.activeChunk

for frame in range(0, chunk.frame_count):

print("\nProcessing frame #" + str(frame + 1) + ": ")

for marker in chunk.markers:

v = marker.positions[frame]
v.size = 4
v.w = 1
v = chunk.transform * v

v.size = 3
if chunk.crs:
v = chunk.crs.project(v)

print( marker.label + " " + str(v.x) + "  " + str(v.y) + " " + str(v.z))
« Last Edit: January 30, 2014, 05:42:41 PM by Alexey Pasumansky »
Best regards,
Alexey Pasumansky,
Agisoft LLC

lmg

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Marker tracking
« Reply #2 on: January 30, 2014, 05:40:32 PM »
Thank you Alexey,
I have tried the script and it works very well.
Only 2 others questions:
1) It is possible to print also the scalebars?
2) How to redirect the printing to a text file?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15354
    • View Profile
Re: Marker tracking
« Reply #3 on: January 30, 2014, 05:56:33 PM »
Hello lmg,

Unfortunately, scale-bars are not accessible via Python in the current version. So a an alternative I can suggest to create a function that will return the distance between two points given as arguments and use it for printing distances between markers with the corresponding labels.

To redirect output to the file you need to insert the following line in the beginning of the script:
Code: [Select]
file = open(path, "wt")assuming that path is a string with filepath, like "d:/output.txt".
The next line should be added to the very end:
Code: [Select]
file.close()And, of course to change all print(...) to  file.write(...)

Another hint is to use path = PhotoScan.app.getSaveFileName() in the beginning  - in this case you'll be asked to specify path and filename in standard Save As dialog.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15354
    • View Profile
Re: Marker tracking
« Reply #4 on: January 30, 2014, 06:30:24 PM »
Hello lmg,

Here's a little bit more complicated version of the script that allows to export scalebars:

Code: [Select]
import PhotoScan
import math

scalebars = {"scale 1": ("point 1", "point 6"),
"scale 2": ("point 2", "point 3"),
"scale 3": ("point 4", "point 3")}


def dist(v1, v2):
result = v2 - v1
result = result.norm()
return result

print("Script started")
doc = PhotoScan.app.document
chunk = doc.activeChunk

if chunk.transform:
T = chunk.transform
else:
T = PhotoScan.Matrix().diag([1,1,1,1])

path = PhotoScan.app.getSaveFileName("Specify export path:")
file = open(path, "wt")


for frame in range(0, chunk.frame_count):

file.write("\nFrame # " + str(frame + 1) + " \n")

file.write("Markers:\n")

for marker in chunk.markers:

v = marker.positions[frame]
v.size = 4
v.w = 1
v = T * v
v.size = 3
if chunk.crs:
v = chunk.crs.project(v)

file.write( marker.label + " " + str(v.x) + "  " + str(v.y) + " " + str(v.z) +"\n")

file.write("Scale-bars:\n")

for scalebar in scalebars.items():

(label, (m1, m2)) = scalebar

for marker in chunk.markers:
if m1 == marker.label:
marker1 = marker
elif m2 == marker.label:
marker2 = marker

scale = dist(marker1.positions[frame], marker2.positions[frame])

s = math.sqrt(T[0,0]*T[0,0] + T[0,1]*T[0,1] + T[0,2]*T[0,2])

file.write(label + "  " + str(scale * s) + "\n")


file.close()
print("\n\nfinished")

However, you need to input scale bar labels and corresponding marker labels manually in the script body, like it is shown in the example (note that marker labels are case sensitive!).

I hope it will work fine for you.

   
Best regards,
Alexey Pasumansky,
Agisoft LLC

lmg

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Marker tracking
« Reply #5 on: January 30, 2014, 07:12:11 PM »
Ok. Thank you very much.

lmg

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Marker tracking
« Reply #6 on: February 05, 2014, 07:27:43 PM »
Dear Alexey,
I have tried today the script with another case, and I receive this error log:

[Script started
Traceback (most recent call last):
  File "P:/Python_batch/corrd-scal_alex.py", line 36, in <module>
    v.size = 4
AttributeError: 'NoneType' object has no attribute 'size'

With the previous model it was OK. I cannot see the differences between the two situations!

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15354
    • View Profile
Re: Marker tracking
« Reply #7 on: February 05, 2014, 07:36:06 PM »
Hello Img,

I need to check if there's more strict requirements for the current chunk, but the first one is that chunk should be referenced.
Best regards,
Alexey Pasumansky,
Agisoft LLC