LoginSignup
9
6

More than 3 years have passed since last update.

Raspberry Pi & Node-REDでQRコードを読み取ってみる

Last updated at Posted at 2019-12-19

この記事は Node-RED Advent Calendar 2019 14日目の記事です。

はじめに

QRコードをカメラで読み取り、QRコードを認識させて見ようと試してみました。
カメラの映像とQRコードを表示させたいためにnode-red-contrib-image-toolsを使用してみました。

利用するデバイス

  • Raspberry Pi 3 (2018-11-13-raspbian-stretch をインストール)
  • USB接続のWebカメラ BUFFALO BSWHD06M

使用したノード

  • node-red 1.0.3
  • node-red-contrib-image-tools 0.2.5
  • node-red-contrib-usbcamera 0.0.6

Node-REDの設定

スクリーンショット 2019-12-19 18.30.20.png

使用したノードはここにありました。

スクリーンショット 2019-12-19 18.29.25.png

Image ノードは

 送られた画像を設定によって変換してくれるノードです。

Viewerノードは

ノードレッドエディター上で画像を表示してくれるスグレモノです。これは便利ですよ。

2d Barcode Decoderノードは

 QRコードおよびData Matrixバーコードをデコードするノードです。

こんな感じになりました。

video-1576749104.2019-12-19 19_01_20.gif

ただし。。。。読み取れず。。。

スクリーンショット 2019-12-19 18.51.52.png

こんなエラーが発生しました。

スクリーンショット 2019-12-19 18.52.28.png

ただし、2D Data Matrix barcodeは、うまく検知する。どういうこと?

フローのソースコードです。


[{"id":"1e33a9ca.e7b606","type":"tab","label":"フロー 1","disabled":false,"info":""},{"id":"e0743022.b16ed","type":"inject","z":"1e33a9ca.e7b606","name":"","topic":"","payload":"","payloadType":"date","repeat":"1","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":300,"wires":[["29aa9988.1d0146"]]},{"id":"29aa9988.1d0146","type":"usbcamera","z":"1e33a9ca.e7b606","filemode":"1","filename":"image01.jpg","filedefpath":"1","filepath":"","fileformat":"jpeg","resolution":"1","name":"","x":350,"y":300,"wires":[["77bc3fb8.51eff","3a3883c0.a7586c"]]},{"id":"998072e0.dc7db","type":"image viewer","z":"1e33a9ca.e7b606","name":"","width":160,"data":"payload","dataType":"msg","x":390,"y":460,"wires":[["438025e.e077cdc"]]},{"id":"c0e4d0d3.2f6a3","type":"debug","z":"1e33a9ca.e7b606","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":810,"y":460,"wires":[]},{"id":"77bc3fb8.51eff","type":"image viewer","z":"1e33a9ca.e7b606","name":"","width":160,"data":"payload","dataType":"msg","x":550,"y":300,"wires":[[]]},{"id":"3a3883c0.a7586c","type":"jimp-image","z":"1e33a9ca.e7b606","name":"","data":"payload","dataType":"msg","ret":"img","parameter1":"0x00000000","parameter1Type":"msg","parameter2":"1","parameter2Type":"msg","parameter3":"","parameter3Type":"msg","parameter4":"","parameter4Type":"msg","parameter5":"","parameter5Type":"msg","parameter6":"","parameter6Type":"msg","parameter7":"","parameter7Type":"msg","parameter8":"","parameter8Type":"msg","parameterCount":0,"jimpFunction":"none","selectedJimpFunction":{"name":"none","fn":"none","description":"Just loads the image.","parameters":[]},"x":210,"y":460,"wires":[["998072e0.dc7db"]]},{"id":"31b685cc.72597a","type":"catch","z":"1e33a9ca.e7b606","name":"","scope":null,"uncaught":false,"x":590,"y":580,"wires":[["18df2c41.877c94"]]},{"id":"18df2c41.877c94","type":"debug","z":"1e33a9ca.e7b606","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":770,"y":580,"wires":[]},{"id":"438025e.e077cdc","type":"2d Barcode Decoder","z":"1e33a9ca.e7b606","name":"","data":"payload","dataType":"msg","specification":"{\"QR\": true, \"dataMatrix\": false, \"tryHarder\": true}","specificationType":"json","x":600,"y":460,"wires":[["c0e4d0d3.2f6a3"]]},{"id":"3ba2b7ef.d2b618","type":"comment","z":"1e33a9ca.e7b606","name":"decode QR","info":"","x":130,"y":240,"wires":[]},{"id":"5de17b3.1c98384","type":"comment","z":"1e33a9ca.e7b606","name":"Catch any errors","info":"","x":600,"y":540,"wires":[]}]

終わりに

node-red-contrib-image-toolsのサンプルにもQRコードを読み取るフローはありましたが同じ状況なので環境のせいかもしれません。
もし、よろしければ試して頂いて動くようでしたら一報を頂ければうれしいです。

9
6
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
6