Browse Source

Generate GIF from output images

Phyks (Lucas Verney) 4 years ago
parent
commit
7093a9c9a8
4 changed files with 36 additions and 11 deletions
  1. 2
    1
      .gitignore
  2. BIN
      door.blend
  3. 22
    10
      emulate.py
  4. 12
    0
      gifmaker.py

+ 2
- 1
.gitignore View File

@@ -1,4 +1,5 @@
1 1
 __pycache__
2
-*.png
3 2
 blob
4 3
 *.blend1
4
+out/*.png
5
+out.gif

BIN
door.blend View File


+ 22
- 10
emulate.py View File

@@ -11,14 +11,13 @@ Script to be run from inside Blender Python scripting window.
11 11
 
12 12
 fps = 5  # Images per second
13 13
 v = 1  # Forward speed, in meters per second
14
+i = 1  # Step number
14 15
 
15 16
 # alpha are the coefficients for the proportionnality between coordinates in
16 17
 # image plane and camera frame, according to pinhole model
17 18
 alpha_x = 100
18 19
 alpha_y = -100
19 20
 
20
-debug = True
21
-
22 21
 
23 22
 def compute_delta_position(v, omega, old_theta):
24 23
     dt = 1 / fps
@@ -62,23 +61,21 @@ def emulate_simple_control_law(nb_steps=float("inf")):
62 61
 
63 62
     Note: (X, Z) in the paper are (X, Y) in Blender.
64 63
     """
64
+    global i
65 65
     pos_object = init_pos_object()
66 66
     scene = bpy.data.scenes["Scene"]
67 67
     basepath = bpy.path.abspath('//')
68
-    render_path = basepath + "/tmp%s.png"
68
+    render_path = basepath + "out/tmp%s.png"
69 69
 
70 70
     # Set render resolution
71 71
     scene.render.resolution_x = 640
72 72
     scene.render.resolution_y = 480
73
-    scene.render.filepath = render_path % ""
73
+    scene.render.filepath = render_path % i
74 74
 
75 75
     scene.camera.rotation_mode = 'XYZ'
76 76
 
77
-    i = 1
78
-    while i <= nb_steps:
79
-        if debug:
80
-            scene.render.filepath = render_path % i
81
-
77
+    j = 1
78
+    while j <= nb_steps:
82 79
         theta = scene.camera.rotation_euler[2]
83 80
         bpy.ops.render.render(write_still=True)
84 81
         tx, ty, r = do_step_simple_control_law(scene.render.filepath, pos_object, theta)
@@ -90,7 +87,22 @@ def emulate_simple_control_law(nb_steps=float("inf")):
90 87
         scene.camera.rotation_euler[2] += r
91 88
 
92 89
         i += 1
90
+        j += 1
93 91
 
94 92
 
95 93
 if __name__ == "__main__":
96
-    emulate_simple_control_law(1)
94
+    if not os.path.isdir(bpy.path.abspath("//") + "out"):
95
+        os.mkdir(bpy.path.abspath("//") + "out")
96
+    try:
97
+        out_list = [int(i.replace(".png", "").replace("tmp", "")) for i in os.listdir(bpy.path.abspath("//") + "out") if i.startswith("tmp")]
98
+        out_list.sort()
99
+    except ValueError:
100
+        out_list = []
101
+    try:
102
+        i = out_list[-1] + 1
103
+    except IndexError:
104
+        pass
105
+    print("======================================")
106
+    print("Found existing steps, starting from", i)
107
+    emulate_simple_control_law(1)
108
+    print("\n\n")

+ 12
- 0
gifmaker.py View File

@@ -0,0 +1,12 @@
1
+#!/usr/bin/env python
2
+
3
+import subprocess
4
+import os
5
+
6
+images_nb = [int(i.replace(".png", "").replace("tmp", ""))
7
+             for i in os.listdir("out") if i.startswith("tmp")]
8
+images_nb.sort()
9
+
10
+subprocess.check_call(["convert", "-delay", "20", "-loop", "0"] +
11
+                      ["out/tmp"+str(i)+".png" for i in images_nb] +
12
+                      ["out.gif"])