Forum

Author Topic: Scaling using stereo cameras  (Read 2086 times)

ahg95

  • Newbie
  • *
  • Posts: 1
    • View Profile
Scaling using stereo cameras
« on: March 23, 2021, 06:58:21 PM »
I'm trying to figure out a way to scale models using the distance between stereo cameras. These cameras would be spaced 1 meter apart and each pair of photographs would be labeled as right1.jpeg and left1.jpeg sequentially. I had found a script written for something similar on the forum here https://www.agisoft.com/forum/index.php?topic=9016.0 but it seems to be out of date and I'm not too familiar with python. Any advice would be great!

Paulo

  • Hero Member
  • *****
  • Posts: 1347
    • View Profile
Re: Scaling using stereo cameras
« Reply #1 on: March 23, 2021, 10:48:23 PM »
Hi ahg,

the following code would work perfectly, if your images are named as left_XXX and right_XXX with XXX being a secuential number:

Code: [Select]
import Metashape
chunk = Metashape.app.document.chunk
cameras = [camera for camera in chunk.cameras if camera.type == Metashape.Camera.Type.Regular]
while cameras:
    camera1 = cameras.pop(0)
    for camera2 in cameras:
        if camera1.label.rsplit("_", 1)[1] == camera2.label.rsplit("_", 1)[1]:
            cameras.remove(camera2)
            scalebar = chunk.addScalebar(camera1, camera2)
            scalebar.reference.distance = 1
            break
print("script finished")

Now if you do not have a Underscore between left/right and number then you would need to modify code with something like

if camera1.label[0] == "l":
    label1 = camera1.label.lstrip('left')
else:
    label1 = camera1.label.lstrip('right')

do the same defining label2 for camera2 inside loop and finally test

        if label1 == label2:

Maybe this can send you a good path!
« Last Edit: March 24, 2021, 12:25:15 PM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor