Forum

Author Topic: Align photo with python VS Align from GUI  (Read 8000 times)

j.seinturier

  • Newbie
  • *
  • Posts: 19
    • View Profile
Align photo with python VS Align from GUI
« on: May 20, 2015, 06:59:17 AM »
Hello,

I've made a project using Python scripting that detect markers on photographs and then make photo alignment. Here is the code:

Code: [Select]
# Accessing photoscan objects
doc = PhotoScan.app.document
chunk = doc.chunk

chunk.crs =  None

chunk.detectMarkers():

# Add scalebars
# I've cut code here as it's quite long. This part check if markers are available and create
# 3 scalebars

# Aliging photographs
print("Aligning photographs.")
chunk.matchPhotos(PhotoScan.HighAccuracy, PhotoScan.GenericPreselection, False, 40000, 1000)
chunk.alignCameras()

This code detect markers, creates 3 scalebars and run photograph alignment.

My problem is that when i run a code from a fresh chunk with 5 photos, the photos are not aligned and i obtain this log:


Detecting markers...
IMG_20150519_125227LRL.jpg: 100 markers
IMG_20150519_125232LRL.jpg: 100 markers
IMG_20150519_125237LRL.jpg: 100 markers
IMG_20150519_125245LRL.jpg: 100 markers
IMG_20150519_125252LRL.jpg: 100 markers
Detected 100 markers.
Creating grid scalebars
    Added scalebar target 12 - target 87 (0.1835m).
    Added scalebar target 2 - target 100 (0.1835m).
    Added scalebar target 2 - target 12 (0.245m).
Aligning photographs.
Detecting points...
photo 1: 39990 points
photo 2: 39967 points
photo 3: 39993 points
photo 4: 39075 points
photo 5: 37071 points
points detected in 4.646 sec
Selecting pairs...
9232 matches found in 0.188 sec
matches combined in 0.002 sec
matches filtered in 0.152 sec
0 of 10 pairs selected in 0 sec
Matching points...
0 matches found in 0.956 sec
matches combined in 0 sec
matches filtered in 0 sec
setting point indices... 0 done in 0 sec
generated 0 tie points, -1.#IND average projections
finished matching in 5.944 sec
selected 0 tracks out of 0 in 0 sec
Finished processing in 5.95 sec (exit code 1)
Estimating camera locations...
processing block: 5 photos
Finished processing in 0.009 sec (exit code 0)


In this case, the photographs are not aligned.

If i modify my script by removing the 7 last lines (about photo matching and align), when i execute the script on a same new chunk and when i choose "Align photos..." from the GUI, the photographs are aligned. See the log:

Detected 100 markers.
Creating grid scalebars
    Added scalebar target 12 - target 87 (0.1835m).
    Added scalebar target 2 - target 100 (0.1835m).
    Added scalebar target 2 - target 12 (0.245m).
Aligning photographs.
Detecting points...
photo 1: 39990 points
photo 2: 39967 points
photo 3: 39993 points
photo 4: 39075 points
photo 5: 37071 points
points detected in 4.668 sec
Selecting pairs...
9248 matches found in 0.19 sec
matches combined in 0.002 sec
matches filtered in 0.349 sec
10 of 10 pairs selected in 0 sec
Matching points...
21255 matches found in 4.237 sec
matches combined in 0.005 sec
matches filtered in 0.881 sec
setting point indices... 2114 done in 0.001 sec
generated 2114 tie points, 3.0965 average projections
removed 131 multiple indices
removed 9 tracks
finished matching in 10.334 sec
selected 1458 tracks out of 2105 in 0.001 sec
Estimating camera locations...
processing block: 5 photos
pair 0 and 2: 709 robust from 743
pair 0 and 1: 724 robust from 742
pair 0 and 4: 716 robust from 731
pair 0 and 3: 691 robust from 727
adding photos 0 and 1 (724 robust)
adding 724 points, 0 far (5.712 threshold), 0 inaccurate, 0 invisible, 0 weak
adjusting: xxxxxxxxxx 132.824 -> 113.061
adding 3 points, 320 far (5.712 threshold), 0 inaccurate, 0 invisible, 0 weak
optimized in 0.025 seconds
adding photo 4 (3 of 5), 100 of 100 used
adding photo 3 (4 of 5), 100 of 100 used
adding photo 2 (5 of 5), 100 of 100 used
adding 285 points, 431 far (5.712 threshold), 0 inaccurate, 0 invisible, 0 weak
adjusting: xxxxxxxxxx 358.254 -> 188.634
adding 774 points, 260 far (5.712 threshold), 0 inaccurate, 0 invisible, 0 weak
adjusting: xxxxxxxxxx 113.192 -> 112.846
adding 215 points, 227 far (5.712 threshold), 0 inaccurate, 0 invisible, 0 weak
optimized in 0.075 seconds
3 sigma filtering...
adjusting: xxxxxxxxxxxxxxxxxxxx 73.1146 -> 23.1223
point variance: 17.9403
adding 625 points, 5 far (53.8209 threshold), 1 inaccurate, 11 invisible, 0 weak
adjusting: xxxxxxxxx 6.9906 -> 6.45695
point variance: 4.59698
adding 7 points, 60 far (13.791 threshold), 0 inaccurate, 7 invisible, 0 weak
adjusting: xxxxxxxxxxxxxxxxxxxx 5.20477 -> 5.11005
point variance: 2.07277
adding 4 points, 78 far (6.21832 threshold), 0 inaccurate, 4 invisible, 0 weak
adjusting: xxxxxxxxxxxxxxx- 4.99117 -> 4.97316
point variance: 1.28841
adding 5 points, 65 far (3.86522 threshold), 0 inaccurate, 1 invisible, 0 weak
adjusting: xxxxxxxxxxx- 5.04302 -> 5.02462
point variance: 1.01485
adding 15 points, 65 far (3.04454 threshold), 0 inaccurate, 0 invisible, 0 weak
optimized in 0.541 seconds
fx 2207.76, fy 2207.76, cx 1315.48, cy 1628.36, k1 0.0158626, k2 -0.0358551, k3 0.0126521
finished sfm in 2.672 seconds
coordinates applied in 0 sec
Finished processing in 13.02 sec (exit code 1)


It seems that the script:

Code: [Select]
chunk.matchPhotos(PhotoScan.HighAccuracy, PhotoScan.GenericPreselection, False, 40000, 1000)
chunk.alignCameras()

does not make the same thing that the command "Align photos..." from the workflow menu (even if within the GUI i've the same parameters for the alignment)

Can you help me please ?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Align photo with python VS Align from GUI
« Reply #1 on: May 21, 2015, 12:56:51 PM »
Hello j.seinturier,

Is the difference in alignment results for GUI and Python reproducible on this project? If so, then maybe you can send the project file saved after the marker detection stage with scale bars added and also the original images used.
Best regards,
Alexey Pasumansky,
Agisoft LLC

PAPA2137

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Align photo with python VS Align from GUI
« Reply #2 on: June 27, 2017, 03:08:32 PM »
I have similar problem, logs and projects vary depending on how I am making photo aligment.  After aligment from gui sparse cloud point is visible in workspace, while using python script seems not to produce any result (but sparse cloud point  stored in Photoscan.Chunk.point_cloud atrribute is not none when i checked it after alignment). Result of each step of processing using python script should be visible in the workspace?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Align photo with python VS Align from GUI
« Reply #3 on: June 27, 2017, 04:06:57 PM »
Hello PAPA2137,

It would be helpful for our understanding, if you can provide the project with two chunks - one processed via GUI and another via API.

Also PhotoScan.Chunk.point_cloud is not related to your projects, so probably you are accessing the chunk of the opened document incorrectly.
If you are running script from GUI, then the opened document can be accessed as:
Code: [Select]
doc = PhotoScan.app.documentand active chunk of this document:
Code: [Select]
chunk = doc.chunk
When you are using PhotoScan.Chunk - you are accessing Chunk class, not any object related to the existing project.
Best regards,
Alexey Pasumansky,
Agisoft LLC

PAPA2137

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Align photo with python VS Align from GUI
« Reply #4 on: June 27, 2017, 11:25:47 PM »
After further research I found that method for saving document( doc.save(path) which is called after each level of computing is not working properly. Newly created chunk from script is created and shown in gui but results of further processing are not showing up in gui (photos aligment, coordinates system change etc.). Log says that project was saved succefully, but it was not. After switching for save method with path and chunk arguments (doc.save(path=path, chunk=[chunk]) almost everything works properly but the next problem is building DEM ( RuntimeError: Empty frame path error shows up). I gave photoscan and photoscan's python admin permissions and I do not know how to solve this problem.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Align photo with python VS Align from GUI
« Reply #5 on: June 28, 2017, 07:32:26 AM »
Hello PAPA2137,

doc.save(path) works as "Save As" function. It creates another document, so chunk variable needs to be re-assigned. I usually suggest to save the document in the beginning and then use doc.save() function without arguments.
Best regards,
Alexey Pasumansky,
Agisoft LLC

ppant

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Re: Align photo with python VS Align from GUI
« Reply #6 on: July 17, 2017, 03:58:13 PM »
Hello
I am working on python script for mosaicing the image. For some project, Align camera is not working ( some of the pictures in middle for the flight line are not aligned). While running through GUI for the same project, I manually find those cameras which are not aligned and align them one by one manually. This way I am not getting any holes in the middle for the final mosaic image. Is there a way to check after running match point and aligned cameras to see which cameras are not aligned and re-align them via a python script. Like in manual process

Thanks

Paras

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Align photo with python VS Align from GUI
« Reply #7 on: July 18, 2017, 07:27:01 PM »
Hello Paras,

You can check which cameras are not aligned (by checking camera.transform) and then pass the list of not aligned cameras to chunk.alignCameras() function as an argument.
Best regards,
Alexey Pasumansky,
Agisoft LLC

ppant

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Re: Align photo with python VS Align from GUI
« Reply #8 on: July 20, 2017, 05:26:21 PM »
Hello,
I re-align missing cameras that are not aligned when I just call chunk.alignCameras(). The code is like this

aligned_photos = []   # empty list
    for camera in chunk.cameras:
        if camera.transform==None:
            aligned_photos.append(camera)
   
    if len(aligned_photos)>0:
        chunk.alignCameras(aligned_photos,1000)
   
   
    doc.save()
   
    PhotoScan.gpu_mask = 1  #GPU devices binary mask
    PhotoScan.cpu_enable = 2  #CPU cores inactive
    chunk.buildDenseCloud(quality=PhotoScan.MediumQuality)

Now When it goes to  chunk.buildDenseCloud(quality=PhotoScan.MediumQuality)  I am getting  RuntimeError: Zero resolution. Can any suggest what  I am doing wrong here.

Thanks