Agisoft Metashape
Agisoft Metashape => Python and Java API => Topic started by: mwillis 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
-
Hello Mark,
I think that something like the following should work (based on the paths to the original images):
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)
-
Hi Alexey, the script works perfectly. You are the best. Thanks.
-
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!
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")
-
Hello Vance,
Have you tried it on the smaller chunk? Probably it is just working very long on the huge number of cameras?
-
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.
-
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.
-
Thank you very much, I will try that.
-
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).
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