Hello,
I'm trying to load the first trigger of a MicaSense RedEdge camera to see if this is possible to load a multispectral project from Python. Everything seems to load properly but, if I change the master channel of the chunk, every channel except default displays the last added image.
So, is it possible to load such project from Python?
Here is my test script :
import PhotoScan as ps
import glob
import os.path as op
doc = ps.app.document
# Clean project
doc.remove(doc.chunks)
# Multispectral image folder
folder = ps.app.getExistingDirectory('Image folder')
images = glob.iglob(op.join(folder, '*.tif'))
chunk = doc.addChunk()
# Load first image to create sensor
chunk.addPhotos([next(images)])
for path in images:
print(path)
if(len(chunk.cameras) > 1):
chunk.remove([chunk.cameras[-1]])
break
new_cam = chunk.addCamera()
new_cam.open(path)
rig_index = int(new_cam.photo.meta['Pix4D/RigCameraIndex'])
print(new_cam.photo.meta['Pix4D/BandName'], new_cam.photo.meta['Pix4D/RigCameraIndex'])
if(rig_index == 0):
new_cam.sensor = sensor
continue
sensor = chunk.sensors[0]
if(sensor.plane_count <= rig_index):
sensor.plane_count = rig_index + 1
print(sensor.plane_count)
new_sensor = sensor.planes[rig_index]
new_sensor.width, new_sensor.height = sensor.width, sensor.height
new_sensor.focal_length = sensor.focal_length
new_sensor.pixel_size = sensor.pixel_size
cam = chunk.cameras[-2]
print(len(cam.planes), rig_index)
# cam.planes[rig_index].open(path)
cam.planes[rig_index].photo = new_cam.photo
cam.planes[rig_index].sensor = new_sensor
chunk.remove([new_cam])
Here is some output I have for the loaded trigger :
>>> chunk = doc.chunk
>>> cam = chunk.cameras[0]
>>> for c in cam.planes:
... print(id(c.photo), c.photo, c.photo.layer, c.key)
...
2016-06-24 11:44:59 556574208 <Photo 'F:/Home/micasense/raw/0000SET_000_0044_1.tif'> 0 0
2016-06-24 11:44:59 556574208 <Photo 'F:/Home/micasense/raw/0000SET_000_0044_2.tif'> 0 0
2016-06-24 11:44:59 556574208 <Photo 'F:/Home/micasense/raw/0000SET_000_0044_3.tif'> 0 0
2016-06-24 11:44:59 556574208 <Photo 'F:/Home/micasense/raw/0000SET_000_0044_4.tif'> 0 0
2016-06-24 11:44:59 556574208 <Photo 'F:/Home/micasense/raw/0000SET_000_0044_5.tif'> 0 0
>>> print(id(cam.photo), cam.photo)
2016-06-24 12:04:38 556574160 <Photo 'F:/Home/micasense/raw/0000SET_000_0044_1.tif'>
With chunk.master_channel set to -1 0000SET_000_0044_1.tif is displayed and with any other value only 0000SET_000_0044_5.tif is displayed.