Forum

Author Topic: chunk.importMarkers working differently than File>Import>Markers  (Read 3281 times)

gchaprnka

  • Newbie
  • *
  • Posts: 14
    • View Profile
I've been working on a short script to process a batch of photo sets taken with a small camera rig (15 cameras). Manually, the process works fine, but I'm noticing a difference when writing the script. First, the manual process:

1) Add Photos
2) Import markers (exported from a photoset of a calibration object with a set of known markers)
3) Align photos

The process continues, but at this point I have a sparse point butt of the subject, aligned to my coordinate system and scaled appropriately.

The code that I'm using to replicate this process (I've set the cwd to the directory with the pics in it already):
Code: [Select]
pics = ["1.jpg","2.jpg","3.jpg","4.jpg","5.jpg","6.jpg","7.jpg","8.jpg","9.jpg","10.jpg","11.jpg","12.jpg","13.jpg","14.jpg","15.jpg"]
chunk = doc.addChunk()
chunk.importMarkers(markerPath)
chunk.addPhotos(pics)
chunk.matchPhotos(accuracy=Metashape.HighAccuracy, generic_preselection=True,reference_preselection=False)
chunk.alignCameras()

When running the script, I get a sparse butt and the targets exist, but are not where I'd expect them to be (relative to the cameras) based on the manual process. I've attached a pair of screenshots showing the different results from manual vs. script. As a side note - manually, it does not matter if markers are imported before or after cameras are aligned, it works either way. Neither way works in the script.
« Last Edit: January 14, 2019, 08:00:54 PM by gchaprnka »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14818
    • View Profile
Re: chunk.importMarkers working differently than File>Import>Markers
« Reply #1 on: January 14, 2019, 08:26:31 PM »
Hello gchaprnka,

According to the provided screenshots the camera labels are different in these two cases. In the second case, via Python script, the camera labels appear without the image file extension and therefore are different from the labels expected by the XML file.

So you need to keep the extensions when loading the images to the chunk:
Code: [Select]
chunk.addPhotos(pics, strip_extensions = False)
Best regards,
Alexey Pasumansky,
Agisoft LLC

gchaprnka

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: chunk.importMarkers working differently than File>Import>Markers
« Reply #2 on: January 14, 2019, 08:37:55 PM »
Thanks for the quick reply! Unfortunately, adding the "strip_extensions = False" has not fixed my issue (See attachment). Any other thoughts?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14818
    • View Profile
Re: chunk.importMarkers working differently than File>Import>Markers
« Reply #3 on: January 14, 2019, 09:06:15 PM »
Hello gchaprnka,

Can you share the XML file used for import? (if the data is sensible, please send it to support@agisoft.com, in this case the PSZ file with the alignment results would be also helpful).
Best regards,
Alexey Pasumansky,
Agisoft LLC

gchaprnka

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: chunk.importMarkers working differently than File>Import>Markers
« Reply #4 on: January 14, 2019, 09:13:07 PM »
Attached is the markers XML. I've emailed you the PSZ of the same scan, with both manual and automatic chunks.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14818
    • View Profile
Re: chunk.importMarkers working differently than File>Import>Markers
« Reply #5 on: January 14, 2019, 09:30:36 PM »
Hello gchaprnka,

Thank you for providing the sample data.

I've tried to import the markers from the Console using chunk.importMarkers() command and it worked as expected.

I'll try to reproduce the complete scripting operation now to see it it makes any difference.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14818
    • View Profile
Re: chunk.importMarkers working differently than File>Import>Markers
« Reply #6 on: January 14, 2019, 10:01:12 PM »
Ah, you've got importMarkers line before actually adding the images to the chunk. So you should just change the order: at first add photos, then import markers.
Best regards,
Alexey Pasumansky,
Agisoft LLC

gchaprnka

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: chunk.importMarkers working differently than File>Import>Markers
« Reply #7 on: January 14, 2019, 10:18:47 PM »
For the benefit of anyone finding this in the future, the golden ticket was the order things happened. ImportMarkers coming after addPhotos, before matchPhotos.
Code: [Select]
pics = ["1.jpg","2.jpg","3.jpg","4.jpg","5.jpg","6.jpg","7.jpg","8.jpg","9.jpg","10.jpg","11.jpg","12.jpg","13.jpg","14.jpg","15.jpg"]
chunk = doc.addChunk()
chunk.addPhotos(pics, strip_extensions = False)
chunk.importMarkers(markerPath)
chunk.matchPhotos(accuracy=Metashape.HighAccuracy, generic_preselection=True,reference_preselection=False)
chunk.alignCameras()

edit: Alexey is right, I also had "strip_extensions = False" added to the addPhotos in my final code. Good catch!
« Last Edit: January 14, 2019, 11:51:53 PM by gchaprnka »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14818
    • View Profile
Re: chunk.importMarkers working differently than File>Import>Markers
« Reply #8 on: January 14, 2019, 10:21:53 PM »
I think you should also modify the final code in the example and add "strip_extensions=False" argument here, since the XML file contains the camera labels with the extension.
Best regards,
Alexey Pasumansky,
Agisoft LLC