LoginSignup
11
9

More than 5 years have passed since last update.

【Python】連番の画像ファイルをOpenCVで簡単に読み込む

Posted at

前回の投稿で吐き出したような連番ファイルを読み込む方法メモ。
【Python】OpenCVで取り込んだビデオデータを連番のjpgファイルで保存

VideoCaptureに変換指定子を利用した構文で渡せます。
下のソースコードの例では、00000.jpg,00001.jpg,00002.jpg … と順に読み込みます。

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import cv2

print(__doc__)

video_input = cv2.VideoCapture("%05d.jpg")

while(video_input.isOpened() == True):
    ret, frame = video_input.read()

    cv2.imshow('frame', frame)
    c = cv2.waitKey(50) & 0xFF
    if c==27: # ESC
        break

video_input.release()
cv2.destroyAllWindows()

C++版だとこんな感じ↓

cv::VideoCapture capture("%05d.jpg");

以上。

11
9
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
11
9