Forum

Author Topic: How to fix animation orientation when taking vertical images from Alexey script  (Read 4837 times)

jkova96

  • Full Member
  • ***
  • Posts: 146
    • View Profile
Hi, to everyone.
I found that this script from Alexey, which you can find on this topic --> https://www.agisoft.com/forum/index.php?topic=11313.0 does not work when using vertical image format.
Vertical image - I suppose 9:16, or 3:4...any image which is higher than wider. My animations look like someone flip over to the side (see picture in attachments).
Also, I'll share one video in which you can visually determine what's wrong - https://youtu.be/Vga_3qIpRMo
Hope you understand
Please help ! Bye

Alexey Pasumansky

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

Video is not available.

And please confirm, if the width<height according to the information in the Tools Menu -> Camera Calibration dialog or whether it is the EXIF Orientation tag applying the image rotation?
Best regards,
Alexey Pasumansky,
Agisoft LLC

jkova96

  • Full Member
  • ***
  • Posts: 146
    • View Profile
Hi Alexey,
Sorry for video.
I deleted video accidentaly, here's what I uploaded to YouTube: https://youtu.be/ZSRGemS78YE?si=jSfKO4rUeHa3u8A1
Please stand by for other informations cause I'm not on my laptop right now. But I think it should be normal, I mean width is clearely lower than height.
Thanks for your reply,
I reply to you back as soon as I get to computer.
Thanks :)

jkova96

  • Full Member
  • ***
  • Posts: 146
    • View Profile
Hi Alexey,
I did screenshot my Camera Calibration dialog.
Down below is screenshot.
It's obviously that first number in resolution is higher than second number.
Don't know what to do If I want to have vertical photos, cause when I look at these numbers it's seems that Agisoft considers these photos as horizontal.
Thanks.
Bye :)

jkova96

  • Full Member
  • ***
  • Posts: 146
    • View Profile
Hi Alexey,
Don't know if you seen my message, but I reply to your message, but there's nothing coming back to me...since then.
For this quote
Quote
Video is not available.
here's video link, again, but this time it should work: https://youtu.be/ZSRGemS78YE?si=jSfKO4rUeHa3u8A1
Quote
And please confirm, if the width<height according to the information in the Tools Menu -> Camera Calibration dialog or whether it is the EXIF Orientation tag applying the image rotation?
Check for screenshots...down below

jkova96

  • Full Member
  • ***
  • Posts: 146
    • View Profile
Hi Alexey,
Did you receive my last messages?
I did not figure it out what do you mean?
Real question is how it's possible that orientation of camera's are in "landscape" mode instead of "portrait"? I shoot with my phone, and I did not edit picture in some software on any way. Every image opener says that picture should be in 3:4 not 4:3 like in Agisoft. Second video (which I send you later) is also deleted cause I saw that nobody watching it. I think that picture in my first post should explain what you get - sideways animation instead of straight up.
Thanks :) Hope to see some answers from you too :/

jkova96

  • Full Member
  • ***
  • Posts: 146
    • View Profile
Anyone any solutions?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14888
    • View Profile
Hello Josip,

Please send the project file with the camera alignment only (no depth maps, dense cloud or mesh needed) to support@agisoft.com, so that we could adjust the animation creation script accordingly.

In the following script the orientation tag should be considered, but it is better to check on the actual project.
To see the difference you need to select all cameras in the Photos pane and use Rotate Right (clockwise) button, then run the script to create a new animation track.


Code: [Select]
import Metashape
import math

chunk = Metashape.app.document.chunk
if chunk.camera_track:
chunk.camera_track = None
animation = chunk.addCameraTrack()
chunk.camera_track = animation
animation.label = "Fly Through"
frames = []
for camera in [camera for camera in chunk.cameras if camera.transform and camera.type == Metashape.Camera.Type.Regular]:
frame = chunk.addCamera()
frame.type = Metashape.Camera.Type.Keyframe
orientation = camera.orientation  #1 = 0deg, 6 = 90deg, 8 = 270deg, 3 = 180deg
deg = 0
if orientation == 1:
deg = 0
elif orientation == 6:
deg = -math.pi/2.
elif orientation == 8:
deg = math.pi
elif orientation == 3:
deg = +math.pi/2.
E = math.cos(deg)
F = math.sin(deg)
rotation = Metashape.Matrix([[E, -F, 0, 0], [F, E, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]])
camera_transform = camera.transform * rotation

frame.transform = camera_transform
#print(frame)
frames.append(frame)
animation.keyframes = frames
print("Finished")
« Last Edit: November 01, 2023, 02:19:33 PM by Alexey Pasumansky »
Best regards,
Alexey Pasumansky,
Agisoft LLC

jkova96

  • Full Member
  • ***
  • Posts: 146
    • View Profile
Hi Alexey,
Before everything else what's need to be written I can say BIG THANKS for the script.
I want to tell you that script works perfectly if your images have 'same' orientation. I wrote 'same' under quote marks becaue when you look at images originally, up is up, and down is down. I also wrote 'same' for fact that i realize that there is no ANY CHANGE in orientation in image sequence from your first script. In my project it's a bit complicated because, accordingly to Agisoft software, I have change in orientation when comes to upper photo sequence.

I realize that from picture (image) 20230802_150449.jpg starts image sequence with different orientation - according to created animation. When additionaly rotated that sequence (3x clockwise) then orientation of animation finally matches original orientation from images. I can send you video - yeah it's 10 minutes long, I know...but it describes what I done when coming to perfect animation - https://youtu.be/uFRe_FWszMM

Here's my project - with pictures and without depth maps and dense point cloud - https://drive.google.com/drive/folders/1IMH6V8iqF9qE2zuU-AXHjOW7HRKu1CrS?usp=sharing
Hope you're using Agisoft at least 1.8.5

I want to know if is somwhow possible to make animation which would be able to recognize true orientation, for term "true" I mean matching image condition with terrain.
Can you maybe implement somehow that in future updates of Agisoft, side by side with horizontal and vertical preset.
 

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14888
    • View Profile
Hello Josip,

I have adjusted the script above, so you need only to rotate the images in the Photos pane to Top-up orientation, not upside down, before using the script.

I can also suggest to switch coordinate system in the Reference pane settings dialog to Local Coordinates and use Reset Transform option from the workspace pane context menu for the chunk, as currently in the project coordinate system is set as WGS84, which is not correct and may lead so some later issues, for example, related to the export.
Best regards,
Alexey Pasumansky,
Agisoft LLC

jkova96

  • Full Member
  • ***
  • Posts: 146
    • View Profile
Hi Alexey,
I'm sorry...maybe there comes to missunderstanding,
you said clockwise so I really understand that as clockwise direction.
It just work fine even applied to that direction. I did not experiment anything with counter-clockwise, I'm supposing that I should go counter-clockwise.

I did not realize, but you notice really well that my project is not in Local coordinate system. I did not change coordinate system but I should do, maybe it will be much easier for software to make orientation of images much better.

I did not even suggest that this might be issue. As you know, or maybe don't, I captured photos with my smartphone and unfortunatelly there was GPS on (cause I forget to switch them off) with accuracy of 10 meters.

Thanks for your advices.
Sorry for any inconvenience caused.

Bye !

J.K.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14888
    • View Profile
Hello Josip,

With the updated script it should work in the following way, tested on the provided data:
- load images to the new project/chunk,
- switch coordinate system from WGS84 to Local Coordinates in the Reference pane settings (since there are no valid coordinates loaded from EXIF),
- run Align Photos process,
- run any further processing operations, if needed,
- check that orientation of the image thumbnails in the Photos pane correspond to the real world - top - up (it was so by default, I haven't rotated any thumbnails),
- run updated script as it.
The result is similar to the one you have in the end of the shared video.
Best regards,
Alexey Pasumansky,
Agisoft LLC