Simple Image upload page for IBM Watson Visual Recognition

  • Import the Flow into your workspace
  • Double click on the Watson Visual-Recognition node and enter your API Key
  • open < app_name >/upload

Optional:

  • Change the string inside includes from trigger action function to set a different trigger

Please refer to : https://github.com/krishnac7/IotImageAnalysis

[{"id":"3d9ff17.bfc5d8e","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"4cec4a50.571c8c","type":"function","z":"3d9ff17.bfc5d8e","name":"Process results","func":"result=[];\nmsg.result.images[0].classifiers.forEach(function(current_value, index, initial_array) {\n          current_value.classes.forEach(function(current_value,index,initial_array){\n              result.push(current_value.class);\n          });\n        });\nmsg.verbal=result.toString();\nreturn msg;","outputs":1,"noerr":0,"x":548.8933410644531,"y":364.6071472167969,"wires":[["8f2487c1.d568c8"]]},{"id":"24ac875a.91483","type":"http in","z":"3d9ff17.bfc5d8e","name":"","url":"/upload","method":"get","upload":false,"swaggerDoc":"","x":121.42855834960938,"y":158.57147216796875,"wires":[["c1ee7131.93efa8"]]},{"id":"c1ee7131.93efa8","type":"template","z":"3d9ff17.bfc5d8e","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<center>\n    <h1>Upload an image here:</h1>\n<form action=\"/uploadsimple_post\" method=\"POST\" enctype=\"multipart/form-data\">\n    <input type=\"file\" name=\"myFile\" />\n    <input type=\"submit\" value=\"Submit\">\n</form>\n</center>","output":"str","x":324.2858581542969,"y":165.71426391601562,"wires":[["f2881741.6879"]]},{"id":"f2881741.6879","type":"http response","z":"3d9ff17.bfc5d8e","name":"","x":484.2858581542969,"y":165.71426391601562,"wires":[]},{"id":"b8e7bef2.e8244","type":"http response","z":"3d9ff17.bfc5d8e","name":"","statusCode":"","headers":{},"x":1043.7501220703125,"y":571.25,"wires":[]},{"id":"28da1b09.9229ec","type":"template","z":"3d9ff17.bfc5d8e","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<center>\n<h1>Image Analysed!</h1>\n<pre>\n{{{payload}}}\n</pre>\n<h4>Classification results:</h4>\n<p>{{verbal}}</p>\n<h1>{{action}}</h1>\n</center>","output":"str","x":959.385009765625,"y":504.80169677734375,"wires":[["b8e7bef2.e8244"]]},{"id":"e9396aab.ddc728","type":"function","z":"3d9ff17.bfc5d8e","name":"process image output","func":"if (msg.req.files[0].mimetype.includes('image')) {\n    msg.payload = `<img src=\"data:image/gif;base64,${msg.payload.toString('base64')}\">`;\n} else {\n    msg.payload = msg.payload.toString();\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":773.5359497070312,"y":447.0357666015625,"wires":[["28da1b09.9229ec","a799e3ab.20bb3"]]},{"id":"cc92bcf.7ffe0c","type":"http in","z":"3d9ff17.bfc5d8e","name":"","url":"/uploadsimple_post","method":"post","upload":true,"swaggerDoc":"","x":133.57144165039062,"y":251.60714721679688,"wires":[["7db092e1.047114"]]},{"id":"7db092e1.047114","type":"change","z":"3d9ff17.bfc5d8e","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"req.files[0].buffer","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":133.9287109375,"y":351.0713806152344,"wires":[["7a402f25.ec066"]]},{"id":"7a402f25.ec066","type":"visual-recognition-v3","z":"3d9ff17.bfc5d8e","name":"","apikey":"","vr-service-endpoint":"https://gateway.watsonplatform.net/visual-recognition/api","image-feature":"classifyImage","lang":"en","x":332.2859191894531,"y":383.21429443359375,"wires":[["4cec4a50.571c8c"]]},{"id":"8f2487c1.d568c8","type":"function","z":"3d9ff17.bfc5d8e","name":"trigger action","func":"if (msg.verbal.includes(\"fire\")){\n    msg.action=\"Fire Detected:Triggering Fire rescue\"\n}\nreturn msg;","outputs":1,"noerr":0,"x":739.2859497070312,"y":334.2856750488281,"wires":[["e9396aab.ddc728"]]},{"id":"a799e3ab.20bb3","type":"switch","z":"3d9ff17.bfc5d8e","name":"","property":"action","propertyType":"msg","rules":[{"t":"cont","v":"Fire","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":975.71435546875,"y":417.1428527832031,"wires":[["a8457bc8.1c97b"]]},{"id":"a8457bc8.1c97b","type":"function","z":"3d9ff17.bfc5d8e","name":"","func":"var msg;\nmsg.payload=\"1\";\nreturn msg;","outputs":1,"noerr":0,"x":1110,"y":340,"wires":[["c4b4db9d.2db8c"]]},{"id":"c4b4db9d.2db8c","type":"debug","z":"3d9ff17.bfc5d8e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1293.5,"y":276,"wires":[]}]

Flow Info

Created 7 years, 5 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • change (x1)
  • debug (x1)
  • function (x4)
  • http in (x2)
  • http response (x2)
  • switch (x1)
  • template (x2)
Other
  • tab (x1)
  • visual-recognition-v3 (x1)

Tags

  • IBM
  • Watson
  • VisualRecognition
  • FILE
  • IMAGE
  • UPLOAD
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option