VidGear はビデオ処理のライブラリ. (ディープラーニングは用いていない).
ビデオの読み込み,書き出し,処理,送受信の機能を持つ.対象は, カメラ,スクリーンからも四方鳥,Webブラウザへの送信,ファイル,その他オンラインのストリーミングである. Python から扱うことができる.
【目次】
【関連する外部ページ】
Windows での Git のインストール: 別ページ »で説明
【関連する外部ページ】
Git の公式ページ: https://git-scm.com/
Windows での Python 3.10,関連パッケージ,Python 開発環境のインストール: 別ページ »で説明
【サイト内の関連ページ】
Python のまとめ: 別ページ »にまとめ
【関連する外部ページ】
Python の公式ページ: https://www.python.org/
Windows での Build Tools for Visual Studio 2022,NVIDIA ドライバ,NVIDIA CUDA ツールキット 11.8,NVIDIA cuDNN v8.6 のインストールと動作確認: 別ページ »で説明
【関連する外部ページ】
コマンドプロンプトを管理者として実行: 別ページ »で説明
PyTorch のページ: https://pytorch.org/index.html
次のコマンドは, PyTorch 2.0 (NVIDIA CUDA 11.8 用) をインストールする. 事前に NVIDIA CUDA のバージョンを確認しておくこと(ここでは,NVIDIA CUDA ツールキット 11.8 が前もってインストール済みであるとする).
python -m pip install -U pip python -m pip install -U torch torchvision torchaudio numpy numba --index-url https://download.pytorch.org/whl/cu118 python -c "import torch; print(torch.__version__, torch.cuda.is_available())"
Windows での FFmpeg のインストール(Windows 上): 別ページ »で説明
公式のページ: https://abhitronix.github.io/vidgear/latest/installation/ によりインストールを行う
コマンドプロンプトを管理者として実行: 別ページ »で説明
python -m pip install -U opencv-python python -m pip pip install -U vidgear[core] python -m pip pip install -U vidgear[asyncio]
公式ページに記載のプログラムのうち1つを実行してみる.
まず,ファイル名 test.mp4 のビデオファイルを準備
Python プログラムを実行する
# import required libraries from vidgear.gears import VideoGear import numpy as np import cv2 # open any valid video stream with stabilization enabled(`stabilize = True`) stream_stab = VideoGear(source="test.mp4", stabilize=True).start() # open same stream without stabilization for comparison stream_org = VideoGear(source="test.mp4").start() # loop over while True: # read stabilized frames frame_stab = stream_stab.read() # check for stabilized frame if Nonetype if frame_stab is None: break # read un-stabilized frame frame_org = stream_org.read() # concatenate both frames output_frame = np.concatenate((frame_org, frame_stab), axis=1) # put text over concatenated frame cv2.putText( output_frame, "Before", (10, output_frame.shape[0] - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 255, 0), 2, ) cv2.putText( output_frame, "After", (output_frame.shape[1] // 2 + 10, output_frame.shape[0] - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 255, 0), 2, ) # Show output window cv2.imshow("Stabilized Frame", output_frame) # check for 'q' key if pressed key = cv2.waitKey(1) & 0xFF if key == ord("q"): break # close output window cv2.destroyAllWindows() # safely close both video streams stream_org.stop() stream_stab.stop()