Forum

Author Topic: Delete duplicate photos?  (Read 4629 times)

mwillis

  • Full Member
  • ***
  • Posts: 140
    • View Profile
Delete duplicate photos?
« on: July 01, 2016, 10:00:07 AM »
Hello, does any have a script that will delete all duplicates of a photo within a chunk?

Thanks,

Mark

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 13912
    • View Profile
Re: Delete duplicate photos?
« Reply #1 on: July 01, 2016, 02:44:53 PM »
Hello Mark,

I think that something like the following should work (based on the paths to the original images):

Code: [Select]
chunk = PhotoScan.app.document.chunk
photos = set()
for camera in list(chunk.cameras):
      if camera.photo.path in photos:
             chunk.remove(camera)
      else:
             photos.add(camera.photo.path)
Best regards,
Alexey Pasumansky,
Agisoft LLC

mwillis

  • Full Member
  • ***
  • Posts: 140
    • View Profile
Re: Delete duplicate photos?
« Reply #2 on: July 01, 2016, 07:42:57 PM »
Hi Alexey, the script works perfectly.  You are the best. Thanks.

Vance

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Delete duplicate photos?
« Reply #3 on: February 24, 2017, 08:03:59 PM »
I realize this is an old topic, but I have virtually the same question. I am attempting to use that code (in version 1.3), but it causes photoscan to lockup. Here is the exact code I am attempting to use. I am sure I am doing something wrong!
Code: [Select]
import PhotoScan

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

print("Script finished")

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 13912
    • View Profile
Re: Delete duplicate photos?
« Reply #4 on: February 24, 2017, 08:21:27 PM »
Hello Vance,

Have you tried it on the smaller chunk? Probably it is just working very long on the huge number of cameras?
Best regards,
Alexey Pasumansky,
Agisoft LLC

Vance

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Delete duplicate photos?
« Reply #5 on: February 24, 2017, 08:29:34 PM »
You are probably exactly right. The chunk was originally 600 photos, but was duplicated (and bounding boxes adjusted) about 16 times to aid in processing, then merged back together. The resulting merged chunk has nearly 10,000 photos.

This is my first foray into processing this way, I may not have done it correctly!

Thank you for your quick response.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 13912
    • View Profile
Re: Delete duplicate photos?
« Reply #6 on: February 24, 2017, 08:32:29 PM »
Hello Vance,

The better way to get rid of the duplicate-cameras when you are duplicating the chunks is to group all cameras in every chunk (or in original chunk before duplicating) to the folder and then in the merged chunk you can just remove all but one folders with the duplicates.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Vance

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Delete duplicate photos?
« Reply #7 on: February 24, 2017, 08:33:57 PM »
Thank you very much, I will try that.

Michel

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Delete duplicate photos?
« Reply #8 on: June 17, 2022, 11:53:06 AM »
Hello Vance,

I'm taking the liberty of reviving this old post, because I was faced with the same problem as you for a project with over 50,000 images. In this case, searching in a list takes time and it is better to use a dictionary which by design has a uniformity of keywords.

Here is a script of a function that allows you to disable redundant images. If you want to delete them, you have to adapt it using part of Alexey's code (creation of a list of cameras to delete).

Code: [Select]
import Metashape

app = Metashape.app
doc = Metashape.app.document
chunk = doc.chunk

def disabledDuplicate():
    b = dict()
    for camera in chunk.cameras:
        len_start = len(b)
        b[camera.label] = []
        len_end = len(b)

        if len_start == len_end:
            camera.enabled = False
        else:
            camera.enabled = True

--
Michel