LoginSignup
2
10

More than 5 years have passed since last update.

OpenCVはGStreamerパイプラインを直接受け入れてくれるが、注意必要

Last updated at Posted at 2018-02-03

例えば、RPIからUbuntu等へ、GStreamerで画像をストリームで受けとり、UbuntuのOpenCVで処理したいとき、

RPI側のshellでは、例えばこうします。

gst-launch-1.0 -v -e rpicamsrc preview=0 fullscreen=0 vflip=1 ! 'video/x-h264, width=640, height=480, framerate=30/1, profile=high' ! queue ! rtph264pay ! udpsink host=サーバのIPアドレス port=適当なポート番号X

そして、サーバー側(Ubuntu Python)で、

cmd = '-v udpsrc port=X caps="application/x-rtp,media=(string)video,encoding-name=(string)H264" ! rtph264depay ! avdec_h264 ! videoconvert ! appsink'

とかいうパイプラインと記述を準備しておき、それをそのままOpenCVのVideoCaptureメソッドに指定します。pipelineの最後がappsinkです。

cap = cv2.VideoCapture(cmd)

これでサーバー側でストリームを受け取り、OpenCVで処理できます。

注意点: 
1.cv2.VideoCaptureにGstreamerのPipelineを直接書けるというのは、Undocumentedな仕様らしいです。コード以外のどこにも書いてない。
2.パイプラインの記述で、 ! の両側に空白がないと動きません。<- GSteamerのドキュメントに書いてあるところが見つけられなかった。たとえ書いてあったとしても、仕様Bugと言っていいと思う。

2
10
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
10