Forum

Author Topic: Filter Photos By Point - how does Photoscan do this so quickly?  (Read 3829 times)

jamiemccoll1@gmail.com

  • Newbie
  • *
  • Posts: 5
    • View Profile
Filter Photos By Point - how does Photoscan do this so quickly?
« on: January 18, 2018, 08:13:03 AM »
Hello all,

For context, I am using a chunk with 170 cameras and a sparse cloud of 11936 tie points.

Using the right-click "Filter photos by points" option, Photoscan returns the relevant photos in 0.01325 sec.

Using a python script found elsewhere on these forums, shown below, it takes 2.00 sec.

Why is there this much of a difference? How is the right-click function able to perform so much faster?

Code: [Select]
#selects cameras where the projections of the selected tie points do appear
#compatibility: Agisoft PhotoScan Pro 1.2.1

import PhotoScan
import time

doc = PhotoScan.app.document
chunk = doc.chunk
point_cloud = chunk.point_cloud
points = point_cloud.points
projections = point_cloud.projections

npoints = len(points)
selected_photos = []
start_time = time.time()
for photo in chunk.cameras:

point_index = 0
photo.selected = False
for proj in projections[photo]:
track_id = proj.track_id
while point_index < npoints and points[point_index].track_id < track_id:
point_index += 1
if point_index < npoints and points[point_index].track_id == track_id:
if not points[point_index].valid:
continue
elif points[point_index].selected == True:
photo.selected = True
                                selected_photos.append(photo.label)

PhotoScan.app.update()
end_time = time.time()

print("Time Taken: "+str(end_time-start_time)+" sec")
print("For the selected points the following cameras were used: ")
print(selected_photos)

Edit: code adjustment
« Last Edit: January 18, 2018, 08:27:39 AM by jamiemccoll1@gmail.com »

PolarNick

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
Re: Filter Photos By Point - how does Photoscan do this so quickly?
« Reply #1 on: January 18, 2018, 03:11:30 PM »
Python has very big overhead.

Simple example:

Code: [Select]
x = 0
for i in range(10000000):
    x += (x + i) % 239

This will take 1.05s in Python.

Code: [Select]
int x = 0;
for (int i = 0; i < 10000000; ++i) {
    x += (x + i) % 239;
}

This will take 0.044s and 0.065s in C++ compiled with and without optimizations respectively.

The Python performance is acceptable, until you need to do something in loops thousands of times.

jamiemccoll1@gmail.com

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Filter Photos By Point - how does Photoscan do this so quickly?
« Reply #2 on: January 19, 2018, 01:49:43 AM »
Wow, I had no idea that the two were so different! Thanks for the reply, I hadn't even thought of that aspect.

I guess the follow-up question then - is there anyway to shift the heavy lifting to a C/C++ environment to do these loops more quickly? Or is this not possible with only the python API available to interface with PhotoScan?

PolarNick

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
Re: Filter Photos By Point - how does Photoscan do this so quickly?
« Reply #3 on: January 19, 2018, 11:16:52 AM »
I think it isn't possible to avoid PhotoScan Python API overhead. Because even if you somehow could apply Cython (for example) - you can't get rid of Python layer in PhotoScan API.