-
Notifications
You must be signed in to change notification settings - Fork 18
Sending Camera Snapshots to Amazon Rekognition
This is a quick little flow I pulled together to PoC the usage of Amazon's Rekognition to detect content in my camera snapshots. I have it setup to grab the snapshot when motion is detected, look for objects/labels in the picture, draw a box around them, and then upload the final image to google photos.
For this I used a couple of different nodes and needed to create an account on Amazon AWS to obtain access to Rekognition, and create google photo's account to upload the image to.
- npm i node-red-contrib-image-output - This takes an image passed as a payload and displays it in the workspace.
- npm i node-red-contrib-aws - This is the Amazon AWS SDK.
- npm i node-red-contrib-post-object-detection - This includes the node 'bbox-image', which draws boxes on images. A couple of notes with this package. 1 - It has a second node which is dependant on
Tensor Flow
and will raise an error during install. It is not needed for my use case. 2 - I needed to install these packages to getnode canvas
to installsudo apt-get install build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev
. - npm i NorthernMan54/node-red-contrib-easybotics-gphoto#patch-2 - This is a patched version of the gphoto-uploader that sends a message on upload.
You will need to create an Amazon AWS Account to use Rekognition, details are here.
And once you have created the account, you will need to update the AWS Config node with your region, Access ID and Secret Key. And the Upload Photo with your gphoto account.
Also the flow uses your Desktop directory as a temporary file location prior to uploading to ghoto. The photo file name and path can be changed in the Date/Time Formatter
node.
[{"id":"a031a6c2.0d6e4","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"577815d9.6fd11c","type":"hb-control","z":"a031a6c2.0d6e4","name":"Eufy Porch - Dummy","Homebridge":"Indoor Cam 2K","Manufacturer":"Eufy","Service":"Camera Control","device":"Indoor Cam 2K65:7F:96:9B:5F:C2EufyEufy Porch - Dummy00000111","conf":"6ec121fe.6f7bb","outputs":1,"x":460,"y":60,"wires":[["80b32353.53112","2ba600b6.b7f1e8"]]},{"id":"29c02f88.c9272","type":"debug","z":"a031a6c2.0d6e4","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","x":220,"y":520,"wires":[]},{"id":"e568ed2b.70a048","type":"inject","z":"a031a6c2.0d6e4","name":"Test Button","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":120,"wires":[["577815d9.6fd11c"]]},{"id":"bcf6eccf.bf33c","type":"AWS Rekognition","z":"a031a6c2.0d6e4","aws":"1df182d1.56bc4d","operation":"DetectText","SourceImage":"","TargetImage":"","CollectionId":"","Input":"","Output":"","Name":"","Settings":"","RoleArn":"","FaceIds":"","Image":"","Id":"","JobId":"","FaceId":"","Video":"","name":"","x":430,"y":180,"wires":[[],[]]},{"id":"80b32353.53112","type":"image","z":"a031a6c2.0d6e4","name":"","width":160,"data":"payload","dataType":"msg","thumbnail":false,"active":true,"pass":false,"outputs":0,"x":760,"y":60,"wires":[]},{"id":"2ba600b6.b7f1e8","type":"function","z":"a031a6c2.0d6e4","name":"Convert Image","func":"msg.Image={Bytes:msg.payload};\nmsg.MinConfidence = 90;\nreturn msg;","outputs":1,"noerr":0,"x":160,"y":240,"wires":[["bcf6eccf.bf33c","e82a7359.5bf87","f4592d1c.6462d","7c93d533.4b075c"]]},{"id":"f4592d1c.6462d","type":"AWS Rekognition","z":"a031a6c2.0d6e4","aws":"1df182d1.56bc4d","operation":"DetectLabels","SourceImage":"","TargetImage":"","CollectionId":"","Input":"","Output":"","Name":"","Settings":"","RoleArn":"","FaceIds":"","Image":"","Id":"","JobId":"","FaceId":"","Video":"","name":"","x":430,"y":300,"wires":[["2cbfc01d.f481","17f92c78.6588d4"],[]]},{"id":"2cbfc01d.f481","type":"debug","z":"a031a6c2.0d6e4","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","x":680,"y":220,"wires":[]},{"id":"e82a7359.5bf87","type":"AWS Rekognition","z":"a031a6c2.0d6e4","aws":"1df182d1.56bc4d","operation":"DetectFaces","SourceImage":"","TargetImage":"","CollectionId":"","Input":"","Output":"","Name":"","Settings":"","RoleArn":"","FaceIds":"","Image":"","Id":"","JobId":"","FaceId":"","Video":"","name":"","x":430,"y":240,"wires":[[],[]]},{"id":"7106b589.34da44","type":"debug","z":"a031a6c2.0d6e4","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"true","targetType":"full","x":570,"y":540,"wires":[]},{"id":"3843ca4d.3542ee","type":"hb-event","z":"a031a6c2.0d6e4","name":"Porch Motion","Homebridge":"homebridge","Manufacturer":"Tasmota","Service":"Motion Sensor","device":"homebridgeCC:22:3D:E3:CF:34TasmotaPorch Motion00000085","conf":"6ec121fe.6f7bb","x":170,"y":60,"wires":[["577815d9.6fd11c"]]},{"id":"906ce7e8.d3f178","type":"bbox-image","z":"a031a6c2.0d6e4","strokeWidth":"2","fontSize":"10","objectsProp":"objects","objectsPropType":"msgPayload","imageProp":"image","imagePropType":"msgPayload","name":"","x":390,"y":400,"wires":[["702830db.a11d78","4882845d.79f884"]]},{"id":"702830db.a11d78","type":"image","z":"a031a6c2.0d6e4","name":"","width":160,"data":"payload","dataType":"msg","thumbnail":false,"active":true,"pass":false,"outputs":0,"x":820,"y":460,"wires":[]},{"id":"7fc9aa03.d3aa54","type":"join","z":"a031a6c2.0d6e4","name":"","mode":"custom","build":"merged","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":190,"y":400,"wires":[["906ce7e8.d3f178","29c02f88.c9272"]]},{"id":"7c93d533.4b075c","type":"function","z":"a031a6c2.0d6e4","name":"Convert Image","func":"msg.payload = {};\nmsg.payload.image = msg.Image.Bytes;\ndelete msg.Image;\nreturn msg;\n","outputs":1,"noerr":0,"x":160,"y":320,"wires":[["7fc9aa03.d3aa54"]]},{"id":"fbaf1c4e.e97c1","type":"file","z":"a031a6c2.0d6e4","name":"","filename":"","appendNewline":true,"createDir":false,"overwriteFile":"true","encoding":"none","x":810,"y":400,"wires":[["3f3f0309.8b1124"]]},{"id":"17f92c78.6588d4","type":"function","z":"a031a6c2.0d6e4","name":"BBox","func":"msg.payload.objects = [];\nmsg.payload.Labels.forEach(function(label) {\n if (label.Instances.length > 0 )\n {\n label.Instances.forEach(function(instance){\n msg.payload.objects.push({ bbox: [instance.BoundingBox.Left, instance.BoundingBox.Top, instance.BoundingBox.Width, instance.BoundingBox.Height],\n className: label.Name,\n score: instance.Confidence});\n })\n }\n})\ndelete msg.payload.Labels;\nmsg.complete = true;\nreturn msg;\n/*\n{\"Labels\":[{\"Name\":\"Path\",\"Confidence\":98.61656951904297,\"Instances\":[],\"Parents\":[]},\n{\"Name\":\"Road\",\"Confidence\":96.95530700683594,\"Instances\":[],\"Parents\":[]},\n{\"Name\":\"Furniture\",\"Confidence\":96.45349884033203,\"Instances\":[],\"Parents\":[]},\n{\"Name\":\"Chair\",\"Confidence\":96.45349884033203,\"Instances\":[{\"BoundingBox\":{\"Width\":0.07030118256807327,\"Height\":0.16095371544361115,\"Left\":0.7400304675102234,\"Top\":0.17652830481529236},\"Confidence\":96.45349884033203},{\"BoundingBox\":{\"Width\":0.1145857498049736,\"Height\":0.24060086905956268,\"Left\":0.7839818596839905,\"Top\":0.2865181267261505},\"Confidence\":83.25431060791016}],\"Parents\":[{\"Name\":\"Furniture\"}]},\n{\"Name\":\"Walkway\",\"Confidence\":93.5756607055664,\"Instances\":[],\"Parents\":[{\"Name\":\"Path\"}]},\n{\"Name\":\"Dirt Road\",\"Confidence\":91.7917709350586,\"Instances\":[],\"Parents\":[{\"Name\":\"Road\"}]},\n{\"Name\":\"Gravel\",\"Confidence\":91.7917709350586,\"Instances\":[],\"Parents\":[{\"Name\":\"Road\"}]}],\n\"LabelModelVersion\":\"2.0\"}\n\n{\n bbox: [x, y, w, h],\n className: string,\n score: number\n}\n*/\n","outputs":1,"noerr":0,"x":650,"y":300,"wires":[["7fc9aa03.d3aa54"]]},{"id":"4882845d.79f884","type":"moment","z":"a031a6c2.0d6e4","name":"","topic":"","input":"","inputType":"date","inTz":"America/Toronto","adjAmount":0,"adjType":"days","adjDir":"add","format":"[Desktop/Cottage_Porch_]HH_mm_ss_MMM_D_YYYY[.jpeg]","locale":"en-CA","output":"filename","outputType":"msg","outTz":"America/Toronto","x":620,"y":400,"wires":[["fbaf1c4e.e97c1"]]},{"id":"84c2c346.d2ac48","type":"upload-photo","z":"a031a6c2.0d6e4","name":"","fileName":"","albumName":"CottageRekognition","account":"6777ea6b.c99474","x":600,"y":460,"wires":[["7106b589.34da44","8d1a76e5.8299f"]]},{"id":"cb949dc9.3969b8","type":"debug","z":"a031a6c2.0d6e4","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"true","targetType":"full","x":530,"y":640,"wires":[]},{"id":"3f3f0309.8b1124","type":"function","z":"a031a6c2.0d6e4","name":"Filename","func":"msg.payload = {};\nmsg.payload.fileName = msg.filename;\ndelete msg.Image;\nreturn msg;\n","outputs":1,"noerr":0,"x":420,"y":460,"wires":[["84c2c346.d2ac48","cb949dc9.3969b8"]]},{"id":"8d1a76e5.8299f","type":"file","z":"a031a6c2.0d6e4","name":"Delete","filename":"","appendNewline":true,"createDir":false,"overwriteFile":"delete","encoding":"none","x":760,"y":600,"wires":[[]]},{"id":"6ec121fe.6f7bb","type":"hb-conf","z":"","username":"031-45-154"},{"id":"1df182d1.56bc4d","type":"amazon config","z":"","name":"AWS","region":"us-east-1","proxyRequired":false,"proxy":""},{"id":"6777ea6b.c99474","type":"photo-account","z":""}]