Forum

Author Topic: Change path/replace photos  (Read 16382 times)

Elki

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Change path/replace photos
« Reply #15 on: July 26, 2019, 04:41:59 PM »
Hello,

I'm trying to adapt this script to Metashape, but without success (I'm not competent in python).

I just tried to substitute PhotoScan with Metashape, but when I run it, the software doesn't recognize the attribute "replace".

Code: [Select]
chunk = Metashape.app.document.chunk
for i in range (len(chunk.cameras)):
    chunk.cameras[i].frames[0].path = chunk.cameras[i].path.replace(".dng", ".jpg")

Could anyone help? Thank you!

Elki

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Change path/replace photos
« Reply #16 on: July 26, 2019, 04:50:06 PM »
I just saw in the last version it is possible to change path AND file format with the change path command.

Thank you for this feature!

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14847
    • View Profile
Re: Change path/replace photos
« Reply #17 on: July 26, 2019, 05:23:54 PM »
Hello Elki,

Please let me know, if you have any issues with the file type switching via Change Paths GUI option.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Elki

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Change path/replace photos
« Reply #18 on: July 26, 2019, 05:27:28 PM »
It worked fine. I just "lost" the 10% of the pictures' chunk because the software says those are "resized".

DayGeckoArt

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: Change path/replace photos
« Reply #19 on: April 11, 2022, 04:44:22 AM »
I'm bumping this thread because I had to change the script to work with the current version of Metashape. This is what I used to change tif to jpg. If you want to do it the other way, just swap them.

Also it took me a while to figure out I had to make a file with extension .py and press CTRL+R to select and run it. I kept trying to paste it into the console like you would do with ArcGIS

ch = Metashape.app.document.chunk
for i in range (len(ch.cameras)):
    ch.cameras.photo.path = ch.cameras.photo.path.replace(".tif", ".jpg")

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14847
    • View Profile
Re: Change path/replace photos
« Reply #20 on: April 11, 2022, 08:01:08 PM »
Hello DayGeckoArt,

Seems that you have a typo in the posted script - ch.cameras list element is not defined. Also I suggest to skip Animation track cameras to avoid unexpected issues:

Code: [Select]
ch = Metashape.app.document.chunk
for i in range (len(ch.cameras)):
    if ch.cameras[i].type != Metashape.Camera.Type.Regular:
        continue
    ch.cameras[i].photo.path = ch.cameras[i].photo.path.replace(".tif", ".jpg")
Best regards,
Alexey Pasumansky,
Agisoft LLC

DayGeckoArt

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: Change path/replace photos
« Reply #21 on: April 12, 2022, 04:00:04 AM »
Hello DayGeckoArt,

Seems that you have a typo in the posted script - ch.cameras list element is not defined. Also I suggest to skip Animation track cameras to avoid unexpected issues:

Code: [Select]
ch = Metashape.app.document.chunk
for i in range (len(ch.cameras)):
    if ch.cameras[i].type != Metashape.Camera.Type.Regular:
        continue
    ch.cameras[i].photo.path = ch.cameras[i].photo.path.replace(".tif", ".jpg")

EDIT: Ooops what I pasted above isn't what ended up working. This is what I did that has worked in a couple projects:

Code: [Select]
ch = Metashape.app.document.chunk
for i in range (len(ch.cameras)):
    ch.cameras[i].photo.path = ch.cameras[i].photo.path.replace(".tif", ".jpg")
« Last Edit: April 12, 2022, 04:54:22 AM by DayGeckoArt »