Forum

Author Topic: select cameras by time  (Read 2263 times)

Phogi

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
select cameras by time
« on: August 16, 2018, 07:11:37 AM »
Hi Alexey,

Could you help me with sort camera by time in the python api? I tried

chunk = PhotoScan.app.document.chunk
cameras = chunk.cameras
cam_num = len(cameras)
chunk_N = 0
for i in range(0,cam_num-1,1):
    timestamp = time.mktime(time.strptime(cameras.photo.meta['Exif/DateTime'], '%Y:%m:%d %H:%M:%S'))
    timestamp_next = time.mktime(time.strptime(cameras[i+1].photo.meta['Exif/DateTime'], '%Y:%m:%d %H:%M:%S'))
    if (timestamp_next - timestamp) <= 60:
        cameras.selected = True
        cameras[i+1].selected = True
    else:
        cameras[i+1].selected = False
        break

But it is always not select the cameras, and sometimes select wrong cameras depending on the camera names. I am assuming it needs to sort by time first, however getting a list of camera time does not store the camera id correspondingly.

Thanks a lot for your help,

Kind regards,

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14839
    • View Profile
Re: select cameras by time
« Reply #1 on: August 16, 2018, 12:56:43 PM »
Hello Phogi,

I can suggest something like the following:

Code: [Select]
import PhotoScan, time

STEP = 60 #seconds

chunk = PhotoScan.app.document.chunk

cameras = dict()

for camera in chunk.cameras:
    cameras[time.mktime(time.strptime(camera.photo.meta['Exif/DateTime'], '%Y:%m:%d %H:%M:%S'))] = camera

sorted_by_time = list(cameras.keys())
sorted_by_time.sort()

for i in range(1, len(cameras)-1):
    if sorted_by_time[i] - sorted_by_time[i-1] < STEP:
        cameras[sorted_by_time[i]].selected = True
        cameras[sorted_by_time[i-1]].selected = True
    else:
        cameras[sorted_by_time[i]].selected = False

So here you've got the dictionary that sets correspondence between the timestamp and camera instance. But the code might not work, if there are identical timestamps, since the dictionary doesn't allow to have identical keys.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Phogi

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
Re: select cameras by time
« Reply #2 on: August 21, 2018, 06:07:34 AM »
Hi Alexey,

Thank you! That script helps hugely! I now can split by time, however I'm still not proficient to split and move them into different chunk, or automatically split dictionary into chunks. However I can manually right click and move to new chunk. Just noticed one thing is when I move to new chunk the other photos just moved in chunk2, if I don't click in the reference panel to cancel selected images (when I'm in chunk 1), the images in chunk 2 will be moved together with the ones selected in chunk 1 to the new chunk.

My crappy codes are:

Code: [Select]
import PhotoScan, time

STEP = 60 #seconds

chunk = PhotoScan.app.document.chunk

cameras = dict()
for camera in chunk.cameras:
    cameras[time.mktime(time.strptime(camera.photo.meta['Exif/DateTime'], '%Y:%m:%d %H:%M:%S'))] = camera
#    print('camera',camera)
#    print(cameras[time.mktime(time.strptime(camera.photo.meta['Exif/DateTime'], '%Y:%m:%d %H:%M:%S'))])
#print('Camera', cameras)

chunkcamera = chunk.cameras

sorted_by_time = list(cameras.keys())
sorted_by_time.sort()

chunk_1 = dict()
chunk_2 = dict()
chunk_3 = dict()
chunk_4 = dict()
chunk_5 = dict()
tmpdict = dict()
chunk_initial = 1

for i in range(0, len(cameras)-1):
    tmpkey = []
    tmpkey = sorted_by_time[i]
    if sorted_by_time[i] - sorted_by_time[i-1] < STEP and chunk_initial < 6:
        if chunk_initial == 1:
#            print(cameras[1])
#            chunk_1.update((k,cameras[k]) for k in tmpkey)
            cameras[sorted_by_time[i]].selected = True
        else:
            cameras[sorted_by_time[i]].selected = False
    elif sorted_by_time[i] - sorted_by_time[i-1] > STEP and chunk_initial < 6:
        chunk_initial += 1
    else:
        print('More than 5 chunks, needs increase chunks')


Thanks a lot!