Open DominikVincent opened 4 years ago
@DominikVincent Hi, can you use OpenGL Rendering Engine smoothly? Could you point me to a complete process? Without detailed instructions, it is difficult for me to use it.
@DominikVincent i suggest to create the path of the camera directly in the scene in blender. Then, you can export the location of the camera at each frame to a .csv file. I wrote my own python code, which i inserted in the scripting-part of blender:
import bpy
import numpy as np
def get_location_rotation_from_path(scene, camera, fps):
arr = np.empty((0,8), float)
ts = 0
myRange = range(scene.frame_start, scene.frame_end)
for fr in myRange:
scene.frame_set(fr)
q_norm = np.linalg.norm(cam.matrix_world.decompose()[1][:])
x = cam.matrix_world.decompose()[0][0]
y = cam.matrix_world.decompose()[0][1]
z = cam.matrix_world.decompose()[0][2]
qx = abs(cam.matrix_world.decompose()[1][1]/q_norm)
qy = abs(cam.matrix_world.decompose()[1][2]/q_norm)
qz = abs(cam.matrix_world.decompose()[1][3]/q_norm)
qw = abs(cam.matrix_world.decompose()[1][0]/q_norm)
if cam.matrix_world.decompose()[1][0]/q_norm < 0 or cam.matrix_world.decompose()[1][1]/q_norm <0 or cam.matrix_world.decompose()[1][2]/q_norm<0 or cam.matrix_world.decompose()[1][3]/q_norm <0:
print("Trajectory at frame " + str(fr) + " is smaller than 0!")
tmp_arr = np.hstack((ts, x,y,z,qx,qy,qz,qw))
arr = np.vstack((arr, tmp_arr))
ts += 1/fps*1000000000
return arr
cam = bpy.data.objects["Camera"]
scene = bpy.data.scenes["Scene"]
fps = 20
arr = get_location_rotation_from_path(scene, cam, fps)
arr = np.around(arr, decimals = 6)
print(arr)
header = "timestamp, x, y, z, qx, qy, qz, qw"
np.savetxt("/path_to_output_folder/camera_trajectory.csv", arr, delimiter=', ', header=header,fmt='%1.6f')
print('all done!')
Note the following:
I hope I could help you at least a bit.
Thanks for the answer. However, I am no longer working on my project, but hopefully, it will be useful for others.
Thanks @milmario, really helpful. Works fine for me once I sorted out some blender numpy
issues.
At the end of the line with the big conditional, I think you missed a bit on the last condition, and it should end like:
cam.matrix_world.decompose()[1][3]/q_norm<0:
Hello,
maybe I just do not have enough foreknowledge, but I am confused about trajectories and could not find sufficient documentation. If you could point me to a some sources or answer a few questions that would help.
Thanks a lot for any feedback for my many questions.