Forum

Author Topic: Remove Duplicates Script Not Working 1.6.1  (Read 3087 times)

RoryG

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Remove Duplicates Script Not Working 1.6.1
« on: January 31, 2020, 05:55:17 PM »
Hi,

I use the following script to remove duplicate cameras after merging chunks. Since upgrading to 1.6.1 it fails with the error 'NoneType' object has no attribute 'Path':

Code: [Select]
import Metashape, os

chunk = Metashape.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))

Any help appreciated!

« Last Edit: January 31, 2020, 06:23:49 PM by RoryG »

RoryG

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: Remove Duplicates Script Not Working 1.6.1
« Reply #1 on: February 01, 2020, 12:35:00 PM »
It appears to be something to do with the chunk I'm working on, any ideas what could cause this error?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Remove Duplicates Script Not Working 1.6.1
« Reply #2 on: February 01, 2020, 04:29:58 PM »
Hello RoryG,

Do you have any cameras in the active chunk?

Also are you observing this problem in any project?
Best regards,
Alexey Pasumansky,
Agisoft LLC

RoryG

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: Remove Duplicates Script Not Working 1.6.1
« Reply #3 on: February 03, 2020, 11:27:51 AM »
Hi Alexey,

It's just one merged chunk that's giving me the problem, all the others have worked fine. There are 36,594 cameras in the chunk and there are six of each camera. The chunk is now appended into another project and same issue, so it's something to do with this specific chunk.

Console:

2020-02-03 08:24:05 start
2020-02-03 08:24:06 Traceback (most recent call last):
2020-02-03 08:24:06   File "C:/Users/Rory/Documents/Agisoft/remove_duplicates.py", line 8, in <module>
2020-02-03 08:24:06     if camera.photo.path in paths:
2020-02-03 08:24:06 AttributeError: 'NoneType' object has no attribute 'path'
2020-02-03 08:24:06 Error: 'NoneType' object has no attribute 'path'

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Remove Duplicates Script Not Working 1.6.1
« Reply #4 on: February 03, 2020, 06:10:32 PM »
Hello RoryG,

I can suggest to run the following script for the active Merged chunk to see, if there are any problematic cameras:

Code: [Select]
chunk = Metashape.app.document.chunk
for camera in chunk.cameras:
   if not camera.photo:
      print(camera.label +" - no photo for camera")
      continue
   if not camera.photo.path:
      print(camera.label +" - missing path for camera")
      continue
print("check completed")
« Last Edit: February 03, 2020, 06:43:29 PM by Alexey Pasumansky »
Best regards,
Alexey Pasumansky,
Agisoft LLC

RoryG

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: Remove Duplicates Script Not Working 1.6.1
« Reply #5 on: February 03, 2020, 06:41:01 PM »
Hi,

I ran that script and got this:

2020-02-03 15:39:51 Traceback (most recent call last):
2020-02-03 15:39:51   File "C:/Users/Rory/Documents/Agisoft/check_cameras.py", line 2, in <module>
2020-02-03 15:39:51     for camera in chunk.cameras:
2020-02-03 15:39:51 AttributeError: 'Metashape.Document' object has no attribute 'cameras'
2020-02-03 15:39:51 Error: 'Metashape.Document' object has no attribute 'cameras'

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Remove Duplicates Script Not Working 1.6.1
« Reply #6 on: February 03, 2020, 06:43:59 PM »
Sorry, there was wrong chunk definition - I have corrected it, please try the script now and check, if it prints out any camera labels.
Best regards,
Alexey Pasumansky,
Agisoft LLC

RoryG

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: Remove Duplicates Script Not Working 1.6.1
« Reply #7 on: February 03, 2020, 07:18:46 PM »
Hi Alexey,

It returns 600 "no photo for camera", not sure why as the paths are correct.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Remove Duplicates Script Not Working 1.6.1
« Reply #8 on: February 03, 2020, 08:32:47 PM »
Hello RoryG,

Can you please send chunk.zip and frame.zip to support@agisoft.com for the merged chunk in the problematic project? Also please specify, in which version this chunk has been created.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Remove Duplicates Script Not Working 1.6.1
« Reply #9 on: February 04, 2020, 02:49:39 PM »
Hello RoryG,

Were there any animation camera tracks in the source chunks prior to the merging operation?

Looks like there are many "keyframes" in the merged chunk which are not related to any images. So when removing the duplicates you can only consider the regular cameras:
camera.type == Metashape.Camera.Type.Regular

If you would like to remove the keyframes (which might be no longer accessible in the merged chunk), you can use the following code:
Code: [Select]
chunk = Metashape.app.document
remove_list = list()
for camera in chunk.cameras:
    if camera.type == Metashape.Camera.Type.Keyframe:
        remove_list.append(camera)
chunk.remove(remove_list)
Best regards,
Alexey Pasumansky,
Agisoft LLC

RoryG

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: Remove Duplicates Script Not Working 1.6.1
« Reply #10 on: February 04, 2020, 03:23:49 PM »
Thank you Alexey, that's done the job, I can go ahead and create the ortho now. I did have to modify the remove keyframe script slightly to make it work:

Code: [Select]
import Metashape, os

chunk = Metashape.app.document.chunk
remove_list = list()
for camera in chunk.cameras:
    if camera.type == Metashape.Camera.Type.Keyframe:
        remove_list.append(camera)
chunk.remove(remove_list)

Result:

2020-02-04 12:17:08 start
2020-02-04 12:17:35 disabled 145493660 points
2020-02-04 12:17:36 removed 210384210 tracks
2020-02-04 12:18:07 finished. 30495 duplicates removed

Cheers,

Rory