上一篇完成opencv模塊的創建、編譯、安裝。接下來繼續探索,如何在前端項目中進行調用。
以下內容參考自https://meetrix.io/blog/webrtc/kurento/creating-an-opencv-filter-for-kurento-media-server.html。
模塊創建完成,關於調用的說明如下
- 下載kurento-media-server 官方案例
git clone https://github.com/Kurento/kurento-tutorial-node.git
cd kurento-tutorial-node/kurento-chroma
npm install
可以看一下官方案例中的案例
我們以kurento-chroma爲例,改造並集成我們自己的opencv module。
- 安裝js客戶端
把編譯出來的js客戶端文件夾js 拷貝到kurento-chroma/node_modules目錄下,並把文件夾名稱命名爲package.json中的name名稱
然後需要替換代碼中模塊加載的部分server.js,具體如下
替換依賴的模塊名稱
到這裏基於kurento-chroma 集成自定義模塊helloworld就完成了。然後可以運行服務node server.js 查看運行效果。
運行結果稍後附上。接下來我們進一步來實現js client 給server傳遞參數。比如動態設顯示的文字和位置。需要新增三個變量
textToPrint:輸出的文字內容
positionX:x座標
positionY:y座標
setText(text, x, y)
helloworld.helloworld.json 新增
{
"remoteClasses": [
{
"name": "helloworld",
"extends": "OpenCVFilter",
"doc": "helloworld interface. Documentation about the module",
"constructor": {
"doc": "Create an element",
"params": [
{
"name": "mediaPipeline",
"doc": "the parent :rom:cls:`MediaPipeline`",
"type": "MediaPipeline",
"final": true
}
]
},
"methods":[
{
"name":"setText",
"doc":"Sets the overlay text",
"params":[
{
"name": "text",
"doc": "Text to Print",
"type": "String"
},
{
"name": "x",
"doc": "Position x",
"type": "int"
},
{
"name": "y",
"doc": "Position y",
"type": "int"
}
]
}
]
}
]
}
helloworldOpenCVImpl是helloworldImpl的基類。在基類中實現
子類其實都可以不用做實現
然後重新編譯,如果沒有錯誤,編譯成功。
具體重新編譯過程參考https://meetrix.io/blog/webrtc/kurento/creating-an-opencv-filter-for-kurento-media-server.html。整個過程都是參考這個鏈接。可能需要翻牆。
然後js client 也需要重新編譯。然後把編譯出來的js 文件夾拷貝到kurento-chrom的module目錄下,具體調用方式,需要在創建成功過濾器增加一個定時器,用來捕捉用戶的點擊事件,並調用setText接口,把參數傳入。還有一個地方不是很兩接,現在通過js可以調用服務端的模塊,那服務端的消息如何通知到js客戶端呢?這是個問題。