2
2

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 5 years have passed since last update.

OpenCVで連番付き静止画をビデオリソースとして扱う

Posted at

Visual Tracker Benchmarkに物体追跡用のベンチマークデータがあるが、このデータの実体は連番付きの静止画である。

openCVの VideoCapture メソッドは多機能で、カメラデバイスがあるならカメラから、引数に動画ファイルを与えればその動画ファイルから、そして、連番静止画であれば、次のようにして一連の静止画が動画であるかのように振舞ってくれる。

とても便利

import cv2
import numpy as np
from PIL import Image
import sys

# 4桁連番の jpeg 画像をビデオであるかのように読み込み表示
cap = cv2.VideoCapture('Coupon/img/%04d.jpg')

while True:
    try:
        ok, frame = cap.read()
        cv2.imshow("src",frame)
        if cv2.waitKey(10) == ord('q'):break
    except:
        break
cv2.destroyAllWindows()
cv2.waitKey(1)
2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?