【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}]
相关推荐
思通数科AI全行业智能NLP系统37 分钟前
六大核心应用场景,解锁AI检测系统的智能安全之道
图像处理·人工智能·深度学习·安全·目标检测·计算机视觉·知识图谱
命里有定数2 小时前
Paper -- 洪水深度估计 -- 利用图像处理和深度神经网络绘制街道照片中的洪水深度图
图像处理·人工智能·dnn·洪水深度·高度估计
Ztiddler3 小时前
【npm设置代理-解决npm网络连接error network失败问题】
前端·后端·npm·node.js·vue
前端青山4 小时前
webpack进阶(一)
前端·javascript·webpack·前端框架·node.js
老攀呀6 小时前
安装多个nodejs版本(nvm)
node.js
佚名程序员6 小时前
【Node.js】全面解析 Node.js 安全最佳实践:保护您的应用
安全·node.js
蚂蚁没问题s7 小时前
图像处理 - 色彩空间转换
图像处理·人工智能·算法·机器学习·计算机视觉
zxg_神说要有光18 小时前
快速入门 AI:调用 AI 接口生成 React 组件
前端·javascript·node.js
佚名程序员18 小时前
【Node.js】深入理解 V8 JavaScript 引擎
前端·javascript·node.js
赵闪闪16818 小时前
Node.js 安装与开发环境配置全指南
node.js