Forum

Author Topic: Changing image paths  (Read 5913 times)

MMNN

  • Newbie
  • *
  • Posts: 17
    • View Profile
Changing image paths
« on: March 17, 2016, 12:22:07 PM »
Hey,

I'm trying to copy the image files to a new location and then change the paths in PS to reference the new location and then save the project. The images are copied correctly, and the image paths are changed, but if I close the project and open it again the image paths have changed back to what they were before. It seems like it doesn't save it properly.
If I save it under a different name the new image paths are saved like they are supposed to, but I can't seem to overwrite the old project...

The code where I copy the images:
Code: [Select]
for i in range(len(chunk.cameras)):
imPath = projectDir+'/Images/'+os.path.basename(chunk.cameras[i].photo.path)
shutil.copy(chunk.cameras[i].photo.path, imPath) # copying the image
chunk.cameras[i].photo.path = imPath # setting the new image path
print('copyIm: '+chunk.cameras[i].photo.path)

The code where I save:
Code: [Select]
if not(doc.save(projectPath + "%03d" % projectIncrement + '.psx')):
app.messageBox('Saving project failed!')
print('hej1')
print("%03d" % projectIncrement)
print('--- Saving project to: ' + projectPath + "%03d" % projectIncrement + '.psx')


The output after the save:
Code: [Select]
2016-03-17 09:40:31 Saving project...
2016-03-17 09:40:31 saved project in 0.007 sec
2016-03-17 09:40:32 Finished processing in 0.007 sec (exit code 1)
2016-03-17 09:40:32 hej1
2016-03-17 09:40:32 003
2016-03-17 09:40:32 --- Saving project to: E:/Miriam/Projects/testProjectI/testProjectI003.psx

(The project name is correct, but it still doesn't seem to work)


Any help would be appreciated!

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Changing image paths
« Reply #1 on: March 17, 2016, 12:24:39 PM »
Hello MMNN,

And what output do you get when printing camera path from the first code block?
Best regards,
Alexey Pasumansky,
Agisoft LLC

MMNN

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Changing image paths
« Reply #2 on: March 17, 2016, 01:25:18 PM »
I get
Code: [Select]
2016-03-17 09:40:31 copyIm: E:/Miriam/Projects/testProjectI/Images/DSC_1410.JPG
2016-03-17 09:40:31 copyIm: E:/Miriam/Projects/testProjectI/Images/DSC_1411.JPG
2016-03-17 09:40:31 copyIm: E:/Miriam/Projects/testProjectI/Images/DSC_1412.JPG
2016-03-17 09:40:31 copyIm: E:/Miriam/Projects/testProjectI/Images/DSC_1413.JPG
2016-03-17 09:40:31 copyIm: E:/Miriam/Projects/testProjectI/Images/DSC_1414.JPG
2016-03-17 09:40:31 copyIm: E:/Miriam/Projects/testProjectI/Images/DSC_1487.JPG
2016-03-17 09:40:31 copyIm: E:/Miriam/Projects/testProjectI/Images/DSC_1488.JPG
2016-03-17 09:40:31 copyIm: E:/Miriam/Projects/testProjectI/Images/DSC_1489.JPG
2016-03-17 09:40:31 copyIm: E:/Miriam/Projects/testProjectI/Images/DSC_1490.JPG
2016-03-17 09:40:31 copyIm: E:/Miriam/Projects/testProjectI/Images/DSC_1491.JPG
2016-03-17 09:40:31 copyIm: E:/Miriam/Projects/testProjectI/Images/DSC_1492.JPG
2016-03-17 09:40:31 copyIm: E:/Miriam/Projects/testProjectI/Images/DSC_1493.JPG
2016-03-17 09:40:31 copyIm: E:/Miriam/Projects/testProjectI/Images/DSC_1494.JPG
2016-03-17 09:40:31 copyIm: E:/Miriam/Projects/testProjectI/Images/DSC_1495.JPG
2016-03-17 09:40:31 copyIm: E:/Miriam/Projects/testProjectI/Images/DSC_1496.JPG
2016-03-17 09:40:31 copyIm: E:/Miriam/Projects/testProjectI/Images/DSC_1569.JPG
2016-03-17 09:40:31 copyIm: E:/Miriam/Projects/testProjectI/Images/DSC_1570.JPG
2016-03-17 09:40:31 copyIm: E:/Miriam/Projects/testProjectI/Images/DSC_1571.JPG
2016-03-17 09:40:31 copyIm: E:/Miriam/Projects/testProjectI/Images/DSC_1572.JPG
2016-03-17 09:40:31 copyIm: E:/Miriam/Projects/testProjectI/Images/DSC_1573.JPG
2016-03-17 09:40:31 copyIm: E:/Miriam/Projects/testProjectI/Images/DSC_1574.JPG
2016-03-17 09:40:31 copyIm: E:/Miriam/Projects/testProjectI/Images/DSC_1575.JPG
2016-03-17 09:40:31 copyIm: E:/Miriam/Projects/testProjectI/Images/DSC_1576.JPG
2016-03-17 09:40:31 copyIm: E:/Miriam/Projects/testProjectI/Images/DSC_1577.JPG
2016-03-17 09:40:31 copyIm: E:/Miriam/Projects/testProjectI/Images/DSC_1578.JPG

Which are the right paths

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Changing image paths
« Reply #3 on: March 17, 2016, 01:33:12 PM »
Hello MMNN,

And if you check the paths after saving and closing the project it shows different paths?
Best regards,
Alexey Pasumansky,
Agisoft LLC

MMNN

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Changing image paths
« Reply #4 on: March 17, 2016, 01:37:19 PM »

If I check the image path by right-clicking the image and clicking "show details" right after I run the script, it says:
E:/Miriam/Projects/testProjectI/Images/DSC_1410.JPG
which is what I want.
If I close the file, open it and do the same, it says:
E:/Miriam/Projects/testProjectB/Images/DSC_1410.JPG
which is what it was before...

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Changing image paths
« Reply #5 on: March 17, 2016, 01:48:57 PM »
Hello MMNN,

I think I've managed to reproduce the issue: seems that the path changes via Python are not counted as project changes (at least in PSX), so to avoid that you need to make some changes in the project, like adding/removing new marker or putting the following line doc.chunk = doc.chunk, for example.
Best regards,
Alexey Pasumansky,
Agisoft LLC

MMNN

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Changing image paths
« Reply #6 on: March 17, 2016, 02:06:16 PM »
Thanks Alexey,

Adding and removing a marker worked!!

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Changing image paths
« Reply #7 on: March 17, 2016, 02:27:58 PM »
Hello MMNN,

However, please note that changing photo path is potentially unstable, since thumbnails may be updated in the Photos pane at the same time.

So safe way is the following:
Code: [Select]
photo = camera.photo.copy()
photo.path = new_path
camera.photo = photo
Best regards,
Alexey Pasumansky,
Agisoft LLC

stephan

  • Full Member
  • ***
  • Posts: 129
    • View Profile
Change path to images in script?
« Reply #8 on: April 06, 2016, 12:00:03 PM »
Hi guys,

Does anyone know whether the "change path" function can be scripted? I've searched the documentation but I can't find a way to do this so for now I need to copy my model to a new chunk and import a different set of cameras, but this way I also need to reload the masks which is not ideal.

cheer,