5
5

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

動画からキャプチャ画像を撮る方法(OpenCV)

Last updated at Posted at 2019-11-12

きっかけ

[OpenCVを使って長い動画を一部だけ保存する方法]
(https://qiita.com/satsukiya/items/9647e20c4e27b3d0362a)で取得した1分動画から画像処理のサンプル画像用に好きなところでキャプチャを撮るスクリプトを作ってみたっす:laughing:

開発

Viewを表示して キーボードの s[save] ボタンを押すとキャプチャが保存されます。

import cv2

if __name__ == '__main__':

	cap = cv2.VideoCapture('one_minutes.mp4')
	window_name = "Drop Out NHK"

	save_press_count = 1
	while True:
		presskey = cv2.waitKey(1)

		if not cap.isOpened():
			break

		ret, frame = cap.read()

		if presskey == ord('q'):
			break
		elif presskey == ord('s'):
			cv2.imwrite("capture_{}.png".format(save_press_count), frame)
			# capture ボタンを押しただけ 画像を保存
			save_press_count += 1
		cv2.imshow(window_name,frame)

	cap.release()
	cv2.destroyWindow(window_name)

結果

50302312_378887672660592_5700332032704316718_n.jpg

おわりに

OpenCV 2 プログラミングブック にあったコードを思い出して C++ -> Python に書き換えただけです。
処理用に複数枚の画像が欲しかっただけです。

参考にしたリンク

5
5
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
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?