LoginSignup
0
0

More than 5 years have passed since last update.

OpenViBEのpython frameworkを使ってみる

Posted at

最低限必要なBoxクラス

pythonコードで最低限実装しておくクラスがBoxクラスです。
今回は下記のようなスケルトンコードに必要なものを実装していく形になります

class MyOVBox(OVBox):
    def __init__(self):
        OVBox.__init__(self)

    def initialize(self):
        return

    def process(self):
        return

box = MyOVBox()

__init__()で必要な変数を定義しておきます

initialize()でOpenViBEからのinput値や、setting値を変数に代入します

process()はOpenViBE実行中にループされるメソッドで、実際に動かしたい処理を書きます

試しに書いて動かしてみる

designerで新しくシナリオを作成します

BoxesのScriptingにあるPython scriptingボックスを配置します

Python scriptingボックスを右クリックしてmodify setting > newからName: Threshold, Type: integer, Default value: 10を入力してsettingを追加します

以下のコードをどこかに保存します

class MyOVBox(OVBox):
    def __init__(self):
        OVBox.__init__(self)
        self.count = 0
        self.threshold = 0

    def initialize(self):
        self.threshold = int(self.setting['Threshold']

    def process(self):
        self.count += 1
        print(self.count)

        if self.count >= self.threshold:
            print('Count is threshold!')
            self.count = 0

box = MyOVBox()

Settingで指定したthresholdの値になるまでカウントしていって、threshold値になったら再び0からカウントしなおすだけのコードです

Python scriptingボックスをダブルクリックして、Scriptから先ほど保存したpythonコードを指定します

RUNするとスクリプトが動き、Messageが流れます

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