Forum

Author Topic: Animation to replicate image camera positions ordered by images date and time  (Read 6843 times)

jkova96

  • Full Member
  • ***
  • Posts: 181
    • View Profile
Is there a way how to make animation which can replicate camera positions ordered by capture date and time? Something similar I found on Agisoft Forum, within this link: https://www.agisoft.com/forum/index.php?topic=11313.0 Unfortunately, it seems that this script (in the link above) which is written by Alexey Pasumansky sort cameras positions based on images name in animation. I want to have animation which replicates camera positions ordered by capture date and time of images. Reason for asking you this lays is my project, cause in project I have multiple folders with same image's names but they point out different details on captured construction. Thanks :)

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15366
    • View Profile
Hello jkova96,

You may need to create the list of cameras, sorted by the shooting date and then use it for the keyframes creation.
Something like the following, for example:
Code: [Select]
import Metashape
import datetime, time

chunk = Metashape.app.document.chunk

dict_cams = dict()
cameras = list()
for camera in chunk.cameras:
if (camera.type == Metashape.Camera.Type.Regular) and camera.transform:
date_time = camera.photo.meta['Exif/DateTimeOriginal']
globaltime = time.mktime(time.strptime(date_time, "%Y:%m:%d %H:%M:%S"))
if globaltime in dict_cams.keys():
dict_cams[globaltime].append(camera)
else:
dict_cams[globaltime] = [camera]
keys = list(dict_cams.keys())
keys.sort()
for globaltime in keys:
if len(dict_cams[globaltime]) == 1:
cameras.append(dict_cams[globaltime][0])
else:
for c in dict_cams[globaltime]:
cameras.append(c)

chunk.addCameraTrack()
track = list()
for camera in cameras:
keyframe = chunk.addCamera()
keyframe.type = Metashape.Camera.Type.Keyframe
keyframe.transform = camera.transform #* Metashape.Matrix().Diag([1, -1, -1, 1])
track.append(keyframe)
chunk.camera_tracks[-1].keyframes = track
chunk.camera_track = chunk.camera_tracks[-1]
« Last Edit: August 14, 2023, 05:48:30 PM by Alexey Pasumansky »
Best regards,
Alexey Pasumansky,
Agisoft LLC

jkova96

  • Full Member
  • ***
  • Posts: 181
    • View Profile
Hi Alexey,
I'm so glad that you're answered on my message.
Sorry for waiting for your reply, I was quite busy with other stuff to do.
I tried your algorithm, but I would rather know why, when I use different camera orientation, for example when camera orientation is not horizontal (for example instead of using 16:9, I used 9:16) then longer side of video created from animation stays horizontal. This is especially a problem, when I tried this on my project. Video which I created is available here (YouTube video): https://youtu.be/x_PP1GcbQis
In this video egg stays horizontal, in reality, but it's vertical axis lays on longer side of video. Hope that's clear.
Thanks anyway :) I appreciate that.
Bye :)