基于 Node-red实现opencv边缘检测节点
最近在学习如何将opencv的一些用例以节点的形式加入到Node-red供用户使用,由于opencv边缘检测最简单,所以用其练手,来熟悉下开发流程。node-red上opencv节点基本框架三部分模块构成。
opencv边缘检测模块
基于V8的js调用C++模块
nodejs边缘检测模块
下面是opencv边缘检测模块用例,共有三个函数分别供node-red图像输入节点、图像检测节点和图像输出节点调用,另外使用libuv定时器,用于在各node节点初始化后模拟图像输入,该模块最后将编译成静态库的形式使用。
#include <iostream>
#include <stdlib.h>
#include <unistd.h>
#include <opencv2/opencv.hpp>
#include <string>
#include <uv.h>
#include "cv_edge.h"
using namespace std;
using namespace cv;
//global function and parameter called by timer
static sendMsgCb imageInMsgCb;
static Mat deliverImg;
//the timer to send the mat of image
uv_timer_t imageInTimer;
void timer_cb(uv_timer_t *handle)
{
printDebugMsg("C++ canny", "globalImg: %x", &deliverImg);
imageInMsgCb((unsigned long)&deliverImg);
}
int imageInInit(char *path, sendMsgCb cb){
int ret;
if(cb != NULL){
imageInMsgCb = cb;
}
if(path == NULL){
printDebugMsg("C++ canny&#