Forum

Author Topic: Remove duplicate images  (Read 4274 times)

magic

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Remove duplicate images
« on: December 29, 2017, 02:38:56 PM »
Hi Alexey
Few days ago iv tried this script to remove all duplicate images from my workspace with works well with low number of images :
Code: [Select]
import PhotoScan, os

chunk = PhotoScan.app.document.chunk
print("start")
photos = set()
for camera in list(chunk.cameras):
      if camera.photo.path in photos:
             chunk.remove(camera)
      else:
             photos.add(camera.photo.path)

Problem starts when after few actions like merge etc and several chunks from 60k cameras I go up to 300k(all doubles) and when I tried to started this script its was like turning about 4 hours  without any results , then iv breaked it , takes to long time, did it is possible to optimize this script and get it run faster ?? Iv tried few others(similar pythons scripts) method but no one of them works with PS. Did we vgot some solution Alexey or we cant do it together with PS??

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14855
    • View Profile
Re: Remove duplicate images
« Reply #1 on: December 29, 2017, 04:37:17 PM »
Hello magic,

You can add the camera instances to be removed to the list and then, after the iteration is finished) pass this list to chunk.remove() function.
Best regards,
Alexey Pasumansky,
Agisoft LLC

magic

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Remove duplicate images
« Reply #2 on: December 29, 2017, 05:08:24 PM »
Ok thx will check it next Tuesday,
Have a fun and happy new year

magic

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Remove duplicate images
« Reply #3 on: January 02, 2018, 02:43:47 PM »
Hi Alexey
I cant figured this out Alexey, have to make a list and then go to those list and deleting images in ?
Code: [Select]
import PhotoScan, os

chunk = PhotoScan.app.document.chunk

for camera in chunk.cameras:
    li = ()
    for camera in li:
         chunk.remove(photos)
else:
   
    photos.add(camera.photo.path)


magic

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Remove duplicate images
« Reply #4 on: January 03, 2018, 01:06:07 PM »
Did You can check it Alexey please still have some error at the end of my script
Code: [Select]
import PhotoScan, os

chunk = PhotoScan.app.document.chunk

photos = set()

for photos in list(chunk.cameras):
    print(photos)  #over here i print all my list photos ,think so its ok
    if camera.photo.path in photos:  #<<<<I'v got an error- argument is not iterable
 
        chunk.remove(photos)

    else:
        photos.add(camera.photo)
Why before that worked and now error coming out , what I do wrong Alexey

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14855
    • View Profile
Re: Remove duplicate images
« Reply #5 on: January 03, 2018, 01:15:01 PM »
Hello magic,

Please try this one:

Code: [Select]
import PhotoScan, os

chunk = PhotoScan.app.document.chunk
print("start")
paths = set()
photos = list()
for camera in list(chunk.cameras):
      if camera.photo.path in paths:
             photos.append(camera)
      else:
             paths.add(camera.photo.path)

chunk.remove(photos)
print("finished. %d duplicates removed" % len(photos))
Best regards,
Alexey Pasumansky,
Agisoft LLC

magic

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Remove duplicate images
« Reply #6 on: January 05, 2018, 02:40:10 PM »
Hi Alexey
Works better now
Thanks a lot