0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Multi-Page Tiff で保存された動画をPythonで開く

Last updated at Posted at 2022-04-29

昔 ImageJ で撮影した動画を再生するために

from PIL import Image, ImageSequence # Tiffファイルを開くのに使う
import numpy as np # PILの画像ファイルを numpy の array に変換する
import cv2 # 動画を表示する
import time # フレームレート算出のため

im = Image.open("multi-page.tif")

frames = map(np.asarray, ImageSequence.Iterator(im))

FRAME_RATE = 30
delay = int(1000 / FRAME_RATE)

t = time.time()
for frame in frames:
    # show frame
    cv2.imshow("frame", frame)
    
    # frame rate (viewing)
    _t = time.time()
    print("Frame Rate: {}".format(1.0 / (_t - t)), end="\r")
    
    # press "q" to close window
    if cv2.waitKey(delay) & 0xFF == ord('q'):
        break
    
    t = _t

cv2.destroyWindow("frame")
_ = cv2.waitKey(1)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?