Forum

Author Topic: Export textures from independent cameras  (Read 4788 times)

Pablosg8

  • Newbie
  • *
  • Posts: 6
    • View Profile
Export textures from independent cameras
« on: January 30, 2017, 10:48:16 PM »
Hello, I have a "Photoscan" file with a 3D mesh and a series of cameras prepared to be projected onto the mesh. I need to export each texture generated by each camera to a separate "TIF" file. Is this possible?. I have only been able to automatically export the union of all textures.

Would appreciate any help ...


Code: [Select]
import PhotoScan, os

path = PhotoScan.app.getExistingDirectory("Please choose the folder with .psz files:")

print("Script started")
doc = PhotoScan.app.document
doc.clear()
project_list = os.listdir(path)

for project_name in project_list:
if ".PSZ" in project_name.upper():
doc.open(path + "/" + project_name)
chunk = doc.chunks[0]

chunk.buildTexture(blending=PhotoScan.DisabledBlending, size=4096)

print("Processed project: " + project_name)

chunk.exportModel(path + "/" + project_name[:-3] + "obj", texture_format = 'tif', texture = True, format = "obj")


print("Script finished.")


Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14846
    • View Profile
Re: Export textures from independent cameras
« Reply #1 on: January 31, 2017, 12:33:43 AM »
Hello Pablo,

First of all you need to use buildUV() function before using buildTexture(), unless texture parameterization has been already performed.

As for the separate texture per each camera, you need to disable all but one camera and then blend the texture and export that. It should be repeated for every camera (like disable previously used camera and enable the next one for the texture blending).
Best regards,
Alexey Pasumansky,
Agisoft LLC

Pablosg8

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Export textures from independent cameras
« Reply #2 on: January 31, 2017, 01:41:35 AM »
Thanks for your reply Alexey.

My project already has mapUV in the 3D mesh. I am able to export a TIF texture per camera manually. The problem is that in some projects I have more than 200 cameras and I have to do the work by hand. I have to select a camera, create the texture and export it (so hundreds of times).

My question is if it is possible for a script to solve that problem ...

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14846
    • View Profile
Re: Export textures from independent cameras
« Reply #3 on: January 31, 2017, 11:12:16 AM »
Hello Pablo,

Actually, I was also speaking about the script.

Below is a part of the code that performs automatic disabling of the cameras and builds the texture based on one camera only and then exports the model and the texture. I'm not posting the parameters to the functions, as you can use your own there.

Code: [Select]
for camera in chunk.cameras:
camera.enabled = False

for camera in chunk.cameras:
camera.enabled = True
chunk.buildTexture(...)
chunk.exportModel(...) #if model should be exported
image = chunk.model.texture()
image.save(export_path) #only for texture export
Best regards,
Alexey Pasumansky,
Agisoft LLC

Pablosg8

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Export textures from independent cameras
« Reply #4 on: January 31, 2017, 01:42:11 PM »
Thanks for answering.

I have been solving my problem with your code. But, I have stopped in this code:


Code: [Select]
import PhotoScan, os

print("Script started")

for camera in chunk.cameras:
camera.enabled = False

for camera in chunk.cameras:
camera.enabled = True
chunk.buildTexture(blending=PhotoScan.DisabledBlending, size=4096)
image = chunk.model.texture()
image.save('C:/Users/Photo.tif')

print("OK.")


I started a file with a 3D mesh, a UV map and a series of cameras ready to be projected. But, I don’t have advanced programming skills and I have two problems, that I don’t know how to solve.

1.  At the begining, the cameras was deselectioned and later they was activating. But they don’t do it one by one. I never have only one camera activated, because the cameras was joining. Thus, I can’t save it one by one.

2.  The saved textures are overwritten because I do not know a way to save it with the same name for each projected camera. Is this possible? To named each texture as the name of its camera.

Thank you very much, I think that soon it will work.
« Last Edit: January 31, 2017, 02:08:21 PM by Pablo Gatón »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14846
    • View Profile
Re: Export textures from independent cameras
« Reply #5 on: January 31, 2017, 03:28:15 PM »
Hello Pablo,

I think you need to add chunk = PhotoScan.app.document.chunk line after first print statement.

Also add camera.enabled = False line after saving the texture.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14846
    • View Profile
Re: Export textures from independent cameras
« Reply #6 on: January 31, 2017, 03:31:21 PM »
As for the save filenames, I suggest the following:

Code: [Select]
image.save('C:/Users/' + camera.label[:-4] + '_texture.tif')
Best regards,
Alexey Pasumansky,
Agisoft LLC

Pablosg8

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Export textures from independent cameras
« Reply #7 on: January 31, 2017, 03:42:15 PM »
Thank you very much, it works perfectly.
If I can do something for you let me know.

I write the code below in case I could be helpful for someone:

Code: [Select]
import PhotoScan, os

print("Script started")

chunk = PhotoScan.app.document.chunk

for camera in chunk.cameras:
camera.enabled = False

for camera in chunk.cameras:
camera.enabled = True
chunk.buildTexture(blending=PhotoScan.DisabledBlending, size=4096)
image = chunk.model.texture()
image.save('C:/Users/' + camera.label[:-4] + '_texture.tif')
camera.enabled = False

print("OK.")

Pablosg8

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Export textures from independent cameras
« Reply #8 on: October 12, 2017, 01:59:44 AM »
Hi Alexey,

I have tried the new version 1.4 and I have verified that the script does not work and gives me error. What has changed in the new version so that it does not work ?.

It can be fixed?

Thank you very much for your help.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14846
    • View Profile
Re: Export textures from independent cameras
« Reply #9 on: October 12, 2017, 10:42:01 AM »
Hello Pablosg8,

Which error do you get in Console pane?
Best regards,
Alexey Pasumansky,
Agisoft LLC

Pablosg8

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Export textures from independent cameras
« Reply #10 on: October 14, 2017, 12:47:01 AM »
I have tested and finally it was all my mistake in naming the folder. The script could not find the folder to save the photos.

I confirm that it works well with version 1.4.0.

Sorry for the confusion and thanks for your quick response.