Forum

Author Topic: Group photos from script  (Read 4627 times)

wangli

  • Newbie
  • *
  • Posts: 17
    • View Profile
Group photos from script
« on: January 17, 2017, 02:12:40 PM »
Hi
I have a group of stereo images. After adding all images to the project, I want to group them into two groups (Left and Right) and import the corresponding camera calibration files with format of Australis. Is this achievable using Python script?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Group photos from script
« Reply #1 on: January 17, 2017, 02:48:42 PM »
Hello wangli,

Are they distinguishable by the file path or filenames?
Best regards,
Alexey Pasumansky,
Agisoft LLC

wangli

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Group photos from script
« Reply #2 on: January 17, 2017, 02:59:53 PM »
Hi Alexey
They are distinguished by “A” and “B” in their filename, e g. IMAGE0001A and IMAGE0001B. Left camera and right camera have different calibration files, and I want to fix them.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Group photos from script
« Reply #3 on: January 18, 2017, 02:35:10 PM »
Hello wangli,

You can use the following script to perform grouping of the cameras in the Workspace pane and assigning different calibrations to "left" and "right" images. Note the paths to the calibration files are defined in the script body.

Code: [Select]
import PhotoScan
chunk = PhotoScan.app.document.chunk

left = chunk.addCameraGroup()
left.label = "Left"
right = chunk.addCameraGroup()
right.label = "Right"

c1 = "/calibrations/left.txt"
c2 = "/calibrations/right.txt"

calibs = dict()
calibs["Left"] = PhotoScan.Calibration()
calibs["Right"] = PhotoScan.Calibration()
calibs["Left"].load(c1, "australis")
calibs["Right"].load(c2, "australis")

sensors = dict()
sensors["Left"] = chunk.addSensor()
sensors["Right"] = chunk.addSensor()
sensors["Left"].label = "Left"
sensors["Right"].label = "Right"

for sensor in sensors.keys():
calib = calibs[sensor]
sensors[sensor].width = calib.width
sensors[sensor].height = calib.height
sensors[sensor].type = calib.type
sensors[sensor].user_calib = calib
sensors[sensor].fixed = True

for camera in chunk.cameras:
if len(camera.label) > 5:
if camera.label[-5] == "A":
camera.group = left
camera.sensor = sensors["Left"]
elif camera.label[-5] == "B":
camera.group = right
camera.sensor = sensors["Right"]

print("ok")
« Last Edit: January 19, 2017, 11:20:32 AM by Alexey Pasumansky »
Best regards,
Alexey Pasumansky,
Agisoft LLC

wangli

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Group photos from script
« Reply #4 on: January 19, 2017, 05:46:58 AM »
Hi Alexey,
Thanks so much. It works well with calibration files of the default Agisoft format, but not for other formats. Should we have to specify the format of calibration files? It is Australis in my project. Besides, pixel size and focal length are written in Australis calibration files, can we read them out and import to the corresponding textboxes in the window of "Camera Calibration".
« Last Edit: January 19, 2017, 06:09:08 AM by wangli »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Group photos from script
« Reply #5 on: January 19, 2017, 11:22:21 AM »
Hello wangli,

I've modified the script, in the upper post, so the paths are now to .txt files and "australis" format is used in the calibration load function.
I think it should work.

The focal length in mm and pixel size in mm are not calibration parameters, but sensor properties, so they are not read when you are loading calibration files.
Best regards,
Alexey Pasumansky,
Agisoft LLC

wangli

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Group photos from script
« Reply #6 on: January 22, 2017, 04:33:30 AM »
Hi Alexey,
It works, thanks again.

Chris_1979

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Group photos from script
« Reply #7 on: February 12, 2019, 08:17:42 PM »
Hi Alex, this script is very similar to what I'm looking for, except that I want to sort the images in to two groups based on the size (width in pixels) of the images.  Half my images will be 4K and the other half will be HD.

It doesn't seem possible to use:        if camera.width == "4096"
                                                                         camera.group = 4K

Is there an attribute of camera. that I can use to sort the images?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Group photos from script
« Reply #8 on: February 13, 2019, 11:37:42 AM »
Hello Chris_1979,

The calibration groups (sensors) would be already sorted automatically by the image resolution, so for grouping the cameras in the Workspace pane you can just check:

Code: [Select]
if camera.sensor.width >= 4096:
   camera.group = 4K
else:
   camera.group = HD

Providing that you have created those groups in advance (in the script).
Best regards,
Alexey Pasumansky,
Agisoft LLC