Forum

Author Topic: How to import markers and use as bounding box in standalone python module  (Read 6891 times)

adamjg

  • Guest
Please can you help me understand the correct flow for detecting markers and providing their coordinates.

I would also like to understand how I can set the bounding box to be limited to the markers in x and y with whatever is required for z.

Current code:

Code: [Select]
import Metashape

doc = Metashape.Document()
chunk = doc.addChunk()

chunk.addPhotos(["1.JPG", "2.JPG", ...])

chunk.detectMarkers()

chunk.importReference(os.getcwd() + "/markers.txt")

chunk.matchPhotos(downscale=1, generic_preselection=False, reference_preselection=False)

...

markers.txt

Code: [Select]
# CoordinateSystem: LOCAL_CS["Local Coordinates (m)",LOCAL_DATUM["Local Datum",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]]]
#Label,X,Y,Z,Error_(m),X_error,Y_error,Z_error,X_est,Y_est,Z_est
target 1,0.750000,0.750000,0.000000,,,,,,,
target 2,0.750000,0.000000,0.000000,,,,,,,
target 3,0.750000,-0.750000,0.000000,,,,,,,
target 4,0.000000,-0.750000,0.000000,,,,,,,
target 5,-0.750000,-0.750000,0.000000,,,,,,,
target 6,-0.750000,0.000000,0.000000,,,,,,,
target 7,-0.750000,0.750000,0.000000,,,,,,,
target 8,0.000000,0.750000,0.000000,,,,,,,

EDIT: Updated code
« Last Edit: May 10, 2020, 01:22:33 PM by adamjg »

SAV

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
Hi adamjg,

This might be helpful:
http://www.pi3dscan.com/index.php/instructions/item/agisoft-how-to-process-a-scan-with-projection

You can also download the python scripts from that website.

All the best.

Regards,
SAV

adamjg

  • Guest
Hi SAV,

Yes I have seen this posted around a few times but it uses markers positioned in the z axis and my case is just x and y.

adamjg

  • Guest
I would expect to be able to do something like:

Code: [Select]
# Sizes in metres
sizeX = 1.5 # 1.5 metres
sizeY = 1.5 # 1.5 metres
sizeZ = 2 # 2 metres

# Center in local coordinate system
centerX = 0
centerY = 0
centerZ = 1

# Center
chunk.region.center = Metashape.Vector([centerX, centerY, centerZ])

# Rotation
chunk.region.rot = Metashape.Matrix([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) # 0 degrees rotation matrix

# Size
chunk.region.size = Metashape.Vector([sizeX, sizeY, sizeZ])

But this does not work due to the different coordinate systems at play.

I have managed to get the center working correctly in X and Y dimensions by using this code:

Code: [Select]
centerX = sum([x.position.x for x in chunk.markers]) / len(chunk.markers)
centerY = sum([y.position.y for y in chunk.markers]) / len(chunk.markers)
centerZ = sum([z.position.z for z in chunk.markers]) / len(chunk.markers)

But still sizing and rotation are off.

SAV

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
Hi adamjg,

As far as I can tell it also uses markers in the X / Y plane based on the floor mat.

Code: [Select]
#  Floormate marker definition 
#
#   py
#   
#   |
#   |
#   |
#   
#   p0 ------------ px

p0 = "target 3"   
px = "target 4"
py = "target 1"

distancepx = 0.7 # Change values is you are not using the A1 floormat posted
distancepy = 0.4 # on www.pi3dscan.com

Have a look at the provided AutoProcess_v2.py script and adjust it to your needs. Note that the script was written in 2016 by Richard Garsthagen, hence it might need some alterations to make it work with the latest version of Metashape.

Regards,
SAV



Hi SAV,

Yes I have seen this posted around a few times but it uses markers positioned in the z axis and my case is just x and y.
« Last Edit: May 12, 2020, 08:19:38 AM by SAV »