使用相机拍照实现图像识别
首先需要下载节点 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码的图片进行输出
<img src="data:image/png;base64,{{msg.image}}"/>
3、将使用相机拍摄并智能识别
将文件路径节点换成webcam相机节点即可实现使用相机拍照并智能识别显示在UI界面。
Webcam节点:需要下载node-red-contrib-webcam
节点,此节点支持多个相机的选择。
4、源码
包含有使用文件和相机识别的源码,导入后记得file in节点中修改文件路径为自己电脑上的图片哦。
[{"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}]
本站资源均来自互联网,仅供研究学习,禁止违法使用和商用,产生法律纠纷本站概不负责!如果侵犯了您的权益请与我们联系!
转载请注明出处: 免费源码网-免费的源码资源网站 » 【Node-Red】使用文件或相机拍摄实现图像识别
发表评论 取消回复