【Node-Red】使用文件或相机拍摄实现图像识别

使用相机拍照实现图像识别

首先需要下载节点 node-red-contrib-tfjs-coco-ssd,下载不上的朋友可以根据【Node-Red】最新版coco-ssd 1.0.6安装方法(windows)文章进行安装。

1、智能识别图片

使用本地文件的形式对图像进行识别

  • 时间戳(inject):作为触发点节点
  • 文件路径(file in):写入需要识别的图像路径,例如:D:\node-redPicture\123.jpeg,在输出中选择buffer流
  • tf coco ssd:此节点中,Threshold为分数阈值(0-1),也可通过传参msg.scoreThreshold 进行修改;
    Model Url为地址,尽量不要改动,修改为连接不成功的地址后node-red后台会崩溃;
    Passthru:可以选择图片显示模式;
    Box colour:当Passthru中选择为做过标注的图片,那就需要对标注颜色做设定
  • msg:在msg节点中设置为与调试输出相同来查看完整输出信息
    payload为数组格式,当识别物体为多种时,都可以显示在数组中,在数组中还显示了标注框位置、类型、打分
    image为buffer类型的数组存放图片内容
    classes为识别类型及数量

2、将识别信息显示在UI界面

根据如上输出的msg,将classes和image 进行输出。

  • base64:需要下载新的节点node-red-node-base64,并将属性改为image,实现对msg.image的buffer转为base64进行输出。
  • 识别信息(text):设置为{``{msg.classes}}实现将识别类型和数量进行输出
  • template:将保存在msg.image中的base64码的图片进行输出
sql 复制代码
<img src="data:image/png;base64,{{msg.image}}"/>

3、将使用相机拍摄并智能识别

将文件路径节点换成webcam相机节点即可实现使用相机拍照并智能识别显示在UI界面。

Webcam节点:需要下载node-red-contrib-webcam节点,此节点支持多个相机的选择。

4、源码

包含有使用文件和相机识别的源码,导入后记得file in节点中修改文件路径为自己电脑上的图片哦。

sql 复制代码
[{"id":"951cc2fe955f0e75","type":"tab","label":"图像识别2","disabled":false,"info":"","env":[]},{"id":"cabe60bfdbc81940","type":"inject","z":"951cc2fe955f0e75","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":210,"y":640,"wires":[["fe59fe71ec5f11ac"]]},{"id":"24114e412c2cc380","type":"tensorflowCoco","z":"951cc2fe955f0e75","name":"","modelUrl":"http://127.0.0.1:1880/coco/model.json","scoreThreshold":0.5,"passthru":"bbox","lineColour":"magenta","x":570,"y":640,"wires":[["8b8e5e51a76d5a90","95e0cee58947b315"]]},{"id":"8b8e5e51a76d5a90","type":"ui_text","z":"951cc2fe955f0e75","group":"6f6c46f5d5c922a6","order":2,"width":0,"height":0,"name":"","label":"识别信息","format":"{{msg.payload[0].class}}","layout":"row-spread","className":"","x":760,"y":600,"wires":[]},{"id":"1837101f551fce5b","type":"ui_template","z":"951cc2fe955f0e75","group":"6f6c46f5d5c922a6","name":"","order":4,"width":0,"height":0,"format":"<img src=\"data:image/png;base64,{{msg.image}}\"/>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","className":"","x":920,"y":640,"wires":[[]]},{"id":"95e0cee58947b315","type":"base64","z":"951cc2fe955f0e75","name":"","action":"","property":"image","x":760,"y":640,"wires":[["1837101f551fce5b"]]},{"id":"fe59fe71ec5f11ac","type":"ui_webcam","z":"951cc2fe955f0e75","name":"","group":"6f6c46f5d5c922a6","order":1,"width":"12","height":"6","countdown":false,"autoStart":false,"hideCaptureButton":false,"showImage":"2","mirror":true,"format":"jpeg","x":380,"y":640,"wires":[["24114e412c2cc380"]]},{"id":"4829dfb95f7b284e","type":"inject","z":"951cc2fe955f0e75","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":310,"y":240,"wires":[["13738fa2d9746405"]]},{"id":"eae555d1fe52e7e7","type":"tensorflowCoco","z":"951cc2fe955f0e75","name":"","modelUrl":"http://127.0.0.1:1880/coco/model.json","scoreThreshold":0.5,"passthru":"bbox","lineColour":"magenta","x":590,"y":240,"wires":[["733a983efa6b687d","103b3ab3b44be50b"]]},{"id":"733a983efa6b687d","type":"ui_text","z":"951cc2fe955f0e75","group":"6f6c46f5d5c922a6","order":2,"width":0,"height":0,"name":"","label":"识别信息","format":"{{msg.payload[0].class}}","layout":"row-spread","className":"","x":780,"y":200,"wires":[]},{"id":"696c782d27d5f7cf","type":"ui_template","z":"951cc2fe955f0e75","group":"6f6c46f5d5c922a6","name":"","order":4,"width":"12","height":"9","format":"<img src=\"data:image/png;base64,{{msg.image}}\"/>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","className":"","x":940,"y":280,"wires":[[]]},{"id":"103b3ab3b44be50b","type":"base64","z":"951cc2fe955f0e75","name":"","action":"","property":"image","x":760,"y":280,"wires":[["696c782d27d5f7cf","4e1f0383e3658067"]]},{"id":"13738fa2d9746405","type":"file in","z":"951cc2fe955f0e75","name":"文件路径","filename":"D:\\node-redPicture\\123.jpeg","filenameType":"str","format":"stream","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":440,"y":240,"wires":[["eae555d1fe52e7e7"]]},{"id":"4e1f0383e3658067","type":"debug","z":"951cc2fe955f0e75","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":990,"y":220,"wires":[]},{"id":"6f6c46f5d5c922a6","type":"ui_group","name":"图像识别","tab":"09e34f5af80a3ab6","order":4,"disp":true,"width":"12","collapse":false,"className":""},{"id":"09e34f5af80a3ab6","type":"ui_tab","name":"dashboard基础节点","icon":"dashboard","order":6,"disabled":false,"hidden":false}]
相关推荐
Pigwantofly33 分钟前
软件工程概论项目(二),node.js的配置,npm的使用与vue的安装
node.js
ZJ_.4 小时前
Electron 沙盒模式与预加载脚本:保障桌面应用安全的关键机制
开发语言·前端·javascript·vue.js·安全·electron·node.js
前端SkyRain5 小时前
后端Node学习项目-用户管理-增删改查
后端·学习·node.js
丁总学Java5 小时前
使用 npm 安装 Yarn
前端·npm·node.js
理想不理想v5 小时前
执行npm run build -- --report后,生产report.html文件是什么?
java·前端·javascript·vue.js·webpack·node.js
ForRunner1237 小时前
在 Node.js 中解决极验验证码:使用 Puppeteer 自动化
运维·node.js·自动化
丁总学Java9 小时前
npm list @types/node 命令用于列出当前项目中 @types/node 包及其依赖关系
前端·npm·node.js
慧都小妮子14 小时前
借助Aapose.Cells ,在 Node.js 中将 Excel 转换为 JSON
node.js·json·excel·aspose.cells
黑曼巴、。;15 小时前
直方图均衡化及Matlab实现
图像处理·计算机视觉·matlab
道不可以打折扣18 小时前
【神经科学学习笔记】基于分层嵌套谱分割(Nested Spectral Partition)模型分析大脑网络整合与分离的局部指标(二)
图像处理·人工智能·笔记·学习·计算机视觉