Created
July 26, 2023 09:35
-
-
Save ympbyc/018cfcd8b732cc1574892c255fc12f6a to your computer and use it in GitHub Desktop.
opencv projection matrix animation in hylang. the setup is too slow for realtime animation. I decide I'd abandon the idea to use 2D graphics for pseudo-3D animation. go with 3D graphics library.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import cv2) | |
(import numpy :as np) | |
(import matplotlib [pyplot :as plt animation :as plt-anim]) | |
(setv fig (.figure plt)) | |
(setv idxs [] ims [] axs []) | |
(defn plot [f] | |
(print f) | |
(.cla plt) | |
(for [i idxs] | |
(let [im (get ims i) ax (get axs i) | |
p-orig (.float32 np [[0 0] [500 0] [0 1400] [500 1400]]) | |
p-trans (.float32 np [[0 0] [500 (* f 10)] [0 1400] [500 (- 1400 (* f 10))]]) | |
mtx (.getPerspectiveTransform cv2 p-orig p-trans) | |
im-transformed (.warpPerspective cv2 im mtx #(500 1400))] | |
(.imshow ax im-transformed)))) | |
(setv num 4) | |
(for [i (range 0 num)] | |
(let [path (.format "/home/norimixer/quicklisp/local-projects/fusuma/paintings/kiji/{:02}.png" i) | |
ax (.add_subplot fig 1 num (- (+ num 1) (+ i 1)))] | |
(.append idxs i) | |
(.append ims (.imread cv2 path 1)) | |
(.append axs ax) | |
(.set_axis_off ax))) | |
(setv anim (.FuncAnimation plt-anim fig plot :interval 100 :frames 20)) | |
(.tight_layout fig) | |
(.subplots_adjust plt :wspace 0 :hspace 0) | |
(.show plt) | |
(.close plt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment