上一篇完成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客户端呢?这是个问题。