Last active
December 9, 2017 12:09
-
-
Save btsimonh/5016fd6d32b8f020ea4661545d0d04ae to your computer and use it in GitHub Desktop.
From Camera motion detect with frame queue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [ | |
| { | |
| "id": "591ff606.f43378", | |
| "type": "tab", | |
| "label": "Flow 6", | |
| "disabled": true, | |
| "info": "" | |
| }, | |
| { | |
| "id": "b43ed4b8.4650d8", | |
| "type": "inject", | |
| "z": "591ff606.f43378", | |
| "name": "Start", | |
| "topic": "", | |
| "payload": "1", | |
| "payloadType": "num", | |
| "repeat": "", | |
| "crontab": "", | |
| "once": false, | |
| "x": 90, | |
| "y": 20, | |
| "wires": [ | |
| [ | |
| "86853981.8d2018" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "fc24e044.8edfe", | |
| "type": "function", | |
| "z": "591ff606.f43378", | |
| "name": "LoadCV", | |
| "func": "var require = global.get('require');\nvar cv = null;\n//try{\n// cv = require.main.require('opencv');\n//} catch(e){\n cv = require('opencv');\n \n//}\n\nvar cvdesc = Object.keys(cv);\nnode.send([null, {payload:cvdesc}]);\nflow.set('cv', cv);\n\nnode.log(\"Starting to create MOG2\");\nbg = cv.BackgroundSubtractor.createMOG2();\nnode.log(\"MOG2 has been created\");\nflow.set('bg', bg);\n\n\nnode.send({payload:1, url:'http://raspberrypi:1880/cam2'});\n//node.send({payload:1, url:'http://127.0.0.1:1880/cam2'});\n\n//node.send({payload:1, url:'http://185.49.168.74:8001/axis-cgi/mjpg/video.cgi'});\n//node.send({payload:1, url:'http://mbewebcam.rhul.ac.uk/mjpg/video.mjpg'});\n", | |
| "outputs": "2", | |
| "noerr": 0, | |
| "x": 280, | |
| "y": 100, | |
| "wires": [ | |
| [ | |
| "2347704c.93c73" | |
| ], | |
| [] | |
| ] | |
| }, | |
| { | |
| "id": "86853981.8d2018", | |
| "type": "function", | |
| "z": "591ff606.f43378", | |
| "name": "Variables and 'frames'", | |
| "func": "\nflow.set(\"area\", 200);\nflow.set(\"width\", 640);\nflow.set(\"height\", ((flow.get('width')*3/4/2)>>0)*2);\n\nflow.set('framestore', []);\nflow.set('currentframe', 0);\nflow.set('nextframe', 0);\n\n\nvar timings = {};\nflow.set('timings', timings);\n\n\nvar frames = flow.get('frames') || {num:0, dropped:0, frames:[]};\n\nframes.deleteall = function(){\n var len = frames.frames.length;\n \n for (var i = 0; i < len; i++){\n frames.droplast();\n }\n frames = {num:0, dropped:0, frames:[]};\n flow.set('frames', frames);\n \n};\n\nframes.droplast = function(){\n var oldframe = frames.frames.shift();\n if (oldframe.images){\n var keys = Object.keys(oldframe.images);\n for (var i = 0; i < keys.length; i++){\n if (oldframe.images[keys[i]]){\n if (oldframe.images[keys[i]].release){\n oldframe.images[keys[i]].release();\n }\n }\n }\n var keys = Object.keys(oldframe.imagesasync);\n for (var i = 0; i < keys.length; i++){\n if (oldframe.imagesasync[keys[i]]){\n if (oldframe.imagesasync[keys[i]].release){\n oldframe.imagesasync[keys[i]].release();\n }\n }\n }\n }\n //node.warn(\"frame lost \"+oldframe.num );\n};\n\nframes.frameinlist = function(f){\n var framecount = frames.frames.length;\n var found = false;\n for (var i = framecount-1; i >= 0; i-- ){\n if (f.num == frames.frames[i].num){\n found = true;\n break;\n }\n }\n return found;\n};\n\n\nflow.set('frames', frames);\n\n\nreturn msg;", | |
| "outputs": 1, | |
| "noerr": 0, | |
| "x": 280, | |
| "y": 20, | |
| "wires": [ | |
| [ | |
| "b5637e1d.bb0e5" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "c4876669.f91ec8", | |
| "type": "http in", | |
| "z": "591ff606.f43378", | |
| "name": "", | |
| "url": "/pubcam4", | |
| "method": "get", | |
| "upload": false, | |
| "swaggerDoc": "", | |
| "x": 620, | |
| "y": 500, | |
| "wires": [ | |
| [ | |
| "895994fb.f64a48" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "a98a58d1.04a0a8", | |
| "type": "debug", | |
| "z": "591ff606.f43378", | |
| "name": "", | |
| "active": false, | |
| "console": "false", | |
| "complete": "true", | |
| "x": 750, | |
| "y": 160, | |
| "wires": [] | |
| }, | |
| { | |
| "id": "b5637e1d.bb0e5", | |
| "type": "function", | |
| "z": "591ff606.f43378", | |
| "name": "set opencv folder", | |
| "func": "var req=global.get('require');\n\nvar proc = req('process');\n\n//proc.env['LD_LIBRARY_PATH'] = '/usr/lib/node_modules/opencv/build/opencv/v6.0.0/Release/node-v48-linux-arm/opencv';\n\nreturn msg;", | |
| "outputs": 1, | |
| "noerr": 0, | |
| "x": 270, | |
| "y": 60, | |
| "wires": [ | |
| [ | |
| "fc24e044.8edfe" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "895994fb.f64a48", | |
| "type": "multipart-encoder", | |
| "z": "591ff606.f43378", | |
| "name": "", | |
| "statusCode": "", | |
| "ignoreMessages": true, | |
| "outputOneNew": false, | |
| "outputIfSingle": false, | |
| "outputIfAll": false, | |
| "globalHeaders": { | |
| "Content-Type": "multipart/x-mixed-replace;boundary=--myboundary", | |
| "Connection": "keep-alive", | |
| "Expires": "Fri, 01 Jan 1990 00:00:00 GMT", | |
| "Cache-Control": "no-cache, no-store, max-age=0, must-revalidate", | |
| "Pragma": "no-cache" | |
| }, | |
| "partHeaders": { | |
| "Content-Type": "image/jpeg" | |
| }, | |
| "destination": "all", | |
| "highWaterMark": "150000", | |
| "x": 860, | |
| "y": 500, | |
| "wires": [ | |
| [] | |
| ] | |
| }, | |
| { | |
| "id": "174dcd7e.c72593", | |
| "type": "function", | |
| "z": "591ff606.f43378", | |
| "name": "'input interval'", | |
| "func": "context.lasttime = context.lasttime || (new Date()).valueOf();\n\nvar now = (new Date()).valueOf();\n\nvar diff = now - context.last;\ncontext.last = now;\n\ncontext.diff = diff;\ncontext.avg = context.avg || diff;\n\ncontext.avg *= 0.995;\ncontext.avg += diff*0.005;\n\ncontext.FPS = 1000/context.diff;\ncontext.FPSavg = 1000/context.avg;\n\nflow.set(\"inputfps\", {fps:context.diff, fpsavg:context.avg});\n\nreturn;", | |
| "outputs": 1, | |
| "noerr": 0, | |
| "x": 780, | |
| "y": 60, | |
| "wires": [ | |
| [] | |
| ] | |
| }, | |
| { | |
| "id": "5c02f28c.e78a8c", | |
| "type": "inject", | |
| "z": "591ff606.f43378", | |
| "name": "", | |
| "topic": "", | |
| "payload": "", | |
| "payloadType": "date", | |
| "repeat": "1", | |
| "crontab": "", | |
| "once": false, | |
| "x": 170, | |
| "y": 600, | |
| "wires": [ | |
| [ | |
| "5d324235.ceb2cc" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "5d324235.ceb2cc", | |
| "type": "function", | |
| "z": "591ff606.f43378", | |
| "name": "", | |
| "func": "\nvar inputfps = flow.get('inputfps');\n\nif (inputfps){\n var keys = Object.keys(inputfps);\n for (var i = 0; i < keys.length; i++){\n node.send([{topic:\"input\"+keys[i], payload:inputfps[keys[i]]}, null]);\n }\n}\n\nvar outputfps = flow.get('outputfps');\n\nif (outputfps){\n var keys = Object.keys(outputfps);\n for (var i = 0; i < keys.length; i++){\n node.send([null, {topic:\"output\"+keys[i], payload:outputfps[keys[i]]}]);\n }\n}\n\nvar output2fps = flow.get('output2fps');\n\nif (output2fps){\n var keys = Object.keys(output2fps);\n for (var i = 0; i < keys.length; i++){\n node.send([null, null, {topic:\"output2\"+keys[i], payload:output2fps[keys[i]]}]);\n }\n}\n\n\n\nreturn;", | |
| "outputs": "3", | |
| "noerr": 0, | |
| "x": 330, | |
| "y": 620, | |
| "wires": [ | |
| [ | |
| "5469a8a4.4b3a38" | |
| ], | |
| [ | |
| "aef6b0cc.3b5af" | |
| ], | |
| [ | |
| "4952fa8d.e82474" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "5469a8a4.4b3a38", | |
| "type": "ui_chart", | |
| "z": "591ff606.f43378", | |
| "name": "", | |
| "group": "885e2c54.00ba2", | |
| "order": 0, | |
| "width": 0, | |
| "height": 0, | |
| "label": "input frame interval", | |
| "chartType": "line", | |
| "legend": "false", | |
| "xformat": "HH:mm:ss", | |
| "interpolate": "linear", | |
| "nodata": "", | |
| "dot": false, | |
| "ymin": "0", | |
| "ymax": "200", | |
| "removeOlder": 1, | |
| "removeOlderPoints": "100", | |
| "removeOlderUnit": "3600", | |
| "cutout": 0, | |
| "useOneColor": false, | |
| "colors": [ | |
| "#1f77b4", | |
| "#aec7e8", | |
| "#ff7f0e", | |
| "#2ca02c", | |
| "#98df8a", | |
| "#d62728", | |
| "#ff9896", | |
| "#9467bd", | |
| "#c5b0d5" | |
| ], | |
| "useOldStyle": false, | |
| "x": 530, | |
| "y": 580, | |
| "wires": [ | |
| [], | |
| [] | |
| ] | |
| }, | |
| { | |
| "id": "aef6b0cc.3b5af", | |
| "type": "ui_chart", | |
| "z": "591ff606.f43378", | |
| "name": "", | |
| "group": "885e2c54.00ba2", | |
| "order": 0, | |
| "width": 0, | |
| "height": 0, | |
| "label": "output frame interval", | |
| "chartType": "line", | |
| "legend": "false", | |
| "xformat": "HH:mm:ss", | |
| "interpolate": "linear", | |
| "nodata": "", | |
| "dot": false, | |
| "ymin": "0", | |
| "ymax": "200", | |
| "removeOlder": 1, | |
| "removeOlderPoints": "100", | |
| "removeOlderUnit": "3600", | |
| "cutout": 0, | |
| "useOneColor": false, | |
| "colors": [ | |
| "#1f77b4", | |
| "#aec7e8", | |
| "#ff7f0e", | |
| "#2ca02c", | |
| "#98df8a", | |
| "#d62728", | |
| "#ff9896", | |
| "#9467bd", | |
| "#c5b0d5" | |
| ], | |
| "useOldStyle": false, | |
| "x": 540, | |
| "y": 620, | |
| "wires": [ | |
| [], | |
| [] | |
| ] | |
| }, | |
| { | |
| "id": "5cdfdbf6.020f54", | |
| "type": "debug", | |
| "z": "591ff606.f43378", | |
| "name": "timings debug", | |
| "active": false, | |
| "console": "false", | |
| "complete": "true", | |
| "x": 500, | |
| "y": 540, | |
| "wires": [] | |
| }, | |
| { | |
| "id": "9bef5195.90b0f", | |
| "type": "function", | |
| "z": "591ff606.f43378", | |
| "name": "store frame", | |
| "func": "var frames = flow.get('frames') || {num:0, frames:[]};\n\nvar time_in = (new Date()).valueOf();\nvar frame = { \n jpeg: msg.payload, \n times:{time_in:time_in}, \n num:frames.num++, \n images:{ jpegdecoded: msg.payload },\n imagesasync:{ },\n \n};\n\n\nif (frames.frames.length < 20){\n frames.frames.push(frame);\n} else {\n frames.dropped = (frames.dropped || 0)+1;\n}\n\nvar now = (new Date).valueOf();\ncontext.laststatus = context.laststatus || now;\ncontext.framesavg = (context.framesavg || 0)*0.9 + frames.frames.length*0.1;\n\nif (now > context.laststatus + 1000){\n var colour = (frames.frames.length > 6)?\"red\":\"green\";\n node.status({fill:colour,shape:\"dot\",text:\"frames:\"+frames.frames.length+\":\"+((context.framesavg*100)>>0)/100+\" dropped:\"+frames.dropped});\n context.laststatus = now;\n}\nreturn {};", | |
| "outputs": 1, | |
| "noerr": 0, | |
| "x": 770, | |
| "y": 100, | |
| "wires": [ | |
| [] | |
| ] | |
| }, | |
| { | |
| "id": "cdf95ad7.3f5e98", | |
| "type": "function", | |
| "z": "591ff606.f43378", | |
| "name": "delete frames", | |
| "func": "var frames = flow.get('frames') || {num:0, frames:[]};\n\nif (frames.deleteall){\n frames.deleteall();\n}\n\n\nreturn msg;", | |
| "outputs": 1, | |
| "noerr": 0, | |
| "x": 220, | |
| "y": 140, | |
| "wires": [ | |
| [ | |
| "2347704c.93c73" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "12b43f39.2a6e51", | |
| "type": "inject", | |
| "z": "591ff606.f43378", | |
| "name": "0.03s", | |
| "topic": "", | |
| "payload": "", | |
| "payloadType": "date", | |
| "repeat": "0.03", | |
| "crontab": "", | |
| "once": false, | |
| "x": 70, | |
| "y": 540, | |
| "wires": [ | |
| [ | |
| "d580e269.62c2d" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "a20ffd40.cbaee", | |
| "type": "function", | |
| "z": "591ff606.f43378", | |
| "name": "start jpeg decode", | |
| "func": "var frames = flow.get('frames') || {num:0, frames:[]};\n\n\nvar framecount = frames.frames.length;\nfor (var i = 0; i < framecount; i++ ){\n if (frames.frames[i].jpeg){\n var f = frames.frames[i];\n var cv = flow.get('cv');\n f.times.jpegdecodestart = (new Date()).valueOf();\n var jpeg = f.jpeg;\n delete f.jpeg;\n \n //node.warn(\"payload len \"+msg.payload.length);\n cv.readImageAsync( jpeg, function(err, mat){ \n try{\n f.jpeg = null;\n f.times.jpegdecodeend = (new Date()).valueOf();\n \n f.times.jpegdecodedur = (f.times.jpegdecodeend - f.times.jpegdecodestart);\n\n if (err){\n node.warn(err);\n return;\n }\n if (mat.width() === 0){\n node.warn(\"Matrix width = \" + mat.width() + \" and height = \" + mat.height() + \" nextframe \" + nextframe);\n return; \n }\n \n if (frames.frameinlist(f)){\n //console.log(\"jpegdecodedone \"+i);\n f.images.jpegdecoded = mat;\n } else {\n mat.release();\n console.log(\"jpegdecodeignored \"+i);\n }\n } catch (e){\n console.log(e);\n }\n });\n break;\n }\n}\n\nreturn msg;\n", | |
| "outputs": 1, | |
| "noerr": 0, | |
| "x": 370, | |
| "y": 260, | |
| "wires": [ | |
| [] | |
| ] | |
| }, | |
| { | |
| "id": "c2d39723.c001a8", | |
| "type": "function", | |
| "z": "591ff606.f43378", | |
| "name": "start resize", | |
| "func": "var frames = flow.get('frames') || {num:0, frames:[]};\n\n\nvar framecount = frames.frames.length;\nfor (var i = 0; i < framecount; i++ ){\n var f = frames.frames[i];\n\n if (f.images){\n if (f.images.jpegdecoded){\n var img = f.images.jpegdecoded;\n delete f.images.jpegdecoded;\n f.imagesasync.jpegdecoded = img;\n var cv = flow.get('cv');\n f.times.resizestart = (new Date()).valueOf();\n img.resize(\n flow.get('width'), \n flow.get('height'), \n function(err, mat){\n f.times.resizeend = (new Date()).valueOf();\n f.times.resizedur = (f.times.resizeend - f.times.resizestart);\n if (frames.frameinlist(f)){\n f.images.resized = mat;\n //console.log(\"rezise done \"+ i);\n } else {\n //console.log(\"rezise lost \"+ i);\n mat.release();\n }\n }\n );\n break;\n }\n }\n}\n\nreturn msg;\n", | |
| "outputs": 1, | |
| "noerr": 0, | |
| "x": 350, | |
| "y": 300, | |
| "wires": [ | |
| [] | |
| ] | |
| }, | |
| { | |
| "id": "187e250b.547a1b", | |
| "type": "function", | |
| "z": "591ff606.f43378", | |
| "name": "start bgsubtract", | |
| "func": "var frames = flow.get('frames') || {num:0, frames:[]};\n\n \n\nvar framecount = frames.frames.length;\nfor (var i = 0; i < framecount; i++ ){\n var f = frames.frames[i];\n\n if (f.images){\n if (f.images.resized){\n var cv = flow.get('cv');\n var bg = flow.get('bg');\n f.times.bgstart = (new Date()).valueOf();\n f.imagesasync.resized = f.images.resized;\n delete f.images.resized;\n \n bg.apply(f.imagesasync.resized, function(err, mat){\n f.times.bgend = (new Date()).valueOf();\n f.times.bgdur = (f.times.bgend - f.times.bgstart);\n if (frames.frameinlist(f)){\n f.images.background = mat;\n } else {\n mat.release();\n }\n });\n break;\n }\n }\n}\n\nreturn msg;\n", | |
| "outputs": 1, | |
| "noerr": 0, | |
| "x": 360, | |
| "y": 340, | |
| "wires": [ | |
| [] | |
| ] | |
| }, | |
| { | |
| "id": "187f667d.41b16a", | |
| "type": "function", | |
| "z": "591ff606.f43378", | |
| "name": "GetContours", | |
| "func": "var frames = flow.get('frames') || {num:0, frames:[]};\n\n \n\nvar framecount = frames.frames.length;\nfor (var i = 0; i < framecount; i++ ){\n var f = frames.frames[i];\n\n if (f.images){\n if (f.images.background){\n var cv = flow.get('cv');\n f.imagesasync.background = f.images.background;\n delete f.images.background;\n\n f.times.countoursstart = (new Date()).valueOf();\n // sync!!!\n f.contours = f.imagesasync.background.findContours(\n cv.RETR_EXTERNAL, \n cv.CHAIN_APPROX_SIMPLE);\n f.times.countoursend = (new Date()).valueOf();\n f.times.countoursdur = (f.times.countoursend - f.times.countoursstart);\n break;\n }\n }\n}\n\nreturn msg;", | |
| "outputs": "1", | |
| "noerr": 0, | |
| "x": 370, | |
| "y": 380, | |
| "wires": [ | |
| [] | |
| ] | |
| }, | |
| { | |
| "id": "7350c561.23cb6c", | |
| "type": "function", | |
| "z": "591ff606.f43378", | |
| "name": "DrawBoxes", | |
| "func": "var frames = flow.get('frames') || {num:0, frames:[]};\n\n \n\nvar framecount = frames.frames.length;\nfor (var i = 0; i < framecount; i++ ){\n var f = frames.frames[i];\n\n if (frames.frames[i].images){\n if (f.imagesasync.jpegdecoded && \n f.imagesasync.background && \n f.contours){\n var cv = flow.get('cv');\n f.contoursdone = f.contours;\n delete f.contours;\n \n var requiredarea = flow.get('area');\n\n f.times.boxesstart = (new Date()).valueOf();\n // sync!!!\n var cnts = f.contoursdone;\n var numcnts = cnts.size();\n var camera = f.imagesasync.jpegdecoded;\n var out = f.imagesasync.background;\n \n if (numcnts){\n var scalex = camera.width()/out.width();\n var scaley = camera.height()/out.height();\n \n var areas = [];\n for (var c = 0; c < numcnts; c++){\n var area = { area:cnts.area(c), index:c };\n areas.push(area);\n }\n var fn = function(a, b){\n return (b.area - a.area);\n }\n areas.sort(fn);\n //node.warn(numcnts + ' ' + util.inspect(areas)); \n \n // draw only the three biggest\n for (var i = 0; ((i < 3) && (i < numcnts)); i++){\n var c = areas[i].index;\n //node.error(areas[i].index + ' '+areas[i].area);\n if (areas[i].area > requiredarea){\n var bounding = cnts.boundingRect(c);\n //node.error(bounding);\n \n // draw onto original camera image\n camera.rectangle([bounding.x*scalex, bounding.y*scaley], [bounding.width*scalex, bounding.height*scaley], [0, 0, 255], 2);\n movementfound = true;\n }\n }\n }\n \n f.times.boxesend = (new Date()).valueOf();\n f.times.boxesdur = (f.times.boxesend - f.times.boxesstart);\n f.images.boxed = f.imagesasync.jpegdecoded;\n delete f.imagesasync.jpegdecoded;\n break;\n }\n }\n}\n\nreturn msg;", | |
| "outputs": "1", | |
| "noerr": 0, | |
| "x": 371, | |
| "y": 419, | |
| "wires": [ | |
| [] | |
| ] | |
| }, | |
| { | |
| "id": "29ef7497.8decdc", | |
| "type": "function", | |
| "z": "591ff606.f43378", | |
| "name": "jpegencode", | |
| "func": "var frames = flow.get('frames') || {num:0, frames:[]};\n\n \n\nvar framecount = frames.frames.length;\nfor (var i = 0; i < framecount; i++ ){\n\n if (frames.frames[i].images){\n var tosend = 'boxed';\n \n var img = frames.frames[i].images[tosend];\n delete frames.frames[i].images[tosend];\n frames.frames[i].imagesasync[tosend] = img;\n \n if (img){\n var f = frames.frames[i];\n var cv = flow.get('cv');\n\n f.times.encstart = (new Date()).valueOf();\n \n img.toBuffer(function(err, data){\n var newmsg = {\n payload: data,\n time_in: msg.time_in,\n framenumber: msg.framenumber\n };\n f.times.encend = (new Date()).valueOf();\n f.times.encdur = (f.times.encend - f.times.encstart);\n\n if (frames.frameinlist(f)){\n f.jpegout = data;\n } else {\n }\n img.release();\n });\n break;\n }\n }\n}\n\nreturn msg;", | |
| "outputs": "1", | |
| "noerr": 0, | |
| "x": 370, | |
| "y": 460, | |
| "wires": [ | |
| [] | |
| ] | |
| }, | |
| { | |
| "id": "94e0bdbd.af10f", | |
| "type": "function", | |
| "z": "591ff606.f43378", | |
| "name": "send", | |
| "func": "var frames = flow.get('frames') || {num:0, frames:[]};\n\nvar framecount = frames.frames.length;\n\nif ((framecount > 0) && (frames.frames[0].jpegout)){\n var f = frames.frames[0];\n msg.payload = f.jpegout;\n delete f.jpegout;\n f.times.time_out = (new Date()).valueOf();\n f.times.time_dur = f.times.time_out - f.times.time_in;\n var newmsg = {\n payload:f.times\n };\n frames.droplast();\n node.send([msg, null] )\n node.send([null, newmsg]);\n}\n\nreturn;", | |
| "outputs": "2", | |
| "noerr": 0, | |
| "x": 353, | |
| "y": 511, | |
| "wires": [ | |
| [ | |
| "512719a6.6a7dd8" | |
| ], | |
| [ | |
| "5cdfdbf6.020f54" | |
| ] | |
| ], | |
| "outputLabels": [ | |
| "", | |
| "times" | |
| ] | |
| }, | |
| { | |
| "id": "5e7ed37.c1fb92c", | |
| "type": "function", | |
| "z": "591ff606.f43378", | |
| "name": "", | |
| "func": "\nreturn msg;", | |
| "outputs": 1, | |
| "noerr": 0, | |
| "x": 100, | |
| "y": 360, | |
| "wires": [ | |
| [ | |
| "187f667d.41b16a", | |
| "7350c561.23cb6c", | |
| "29ef7497.8decdc", | |
| "c2d39723.c001a8", | |
| "187e250b.547a1b" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "dfc7e6dd.cadaf8", | |
| "type": "function", | |
| "z": "591ff606.f43378", | |
| "name": "Get 'frames' for debug", | |
| "func": "msg.payload = flow.get('frames');\nreturn msg;", | |
| "outputs": 1, | |
| "noerr": 0, | |
| "x": 680, | |
| "y": 260, | |
| "wires": [ | |
| [ | |
| "4c63c980.c28ee8" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "e93a0761.782618", | |
| "type": "inject", | |
| "z": "591ff606.f43378", | |
| "name": "", | |
| "topic": "", | |
| "payload": "", | |
| "payloadType": "date", | |
| "repeat": "", | |
| "crontab": "", | |
| "once": false, | |
| "x": 620, | |
| "y": 220, | |
| "wires": [ | |
| [ | |
| "dfc7e6dd.cadaf8" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "4c63c980.c28ee8", | |
| "type": "debug", | |
| "z": "591ff606.f43378", | |
| "name": "", | |
| "active": true, | |
| "console": "false", | |
| "complete": "false", | |
| "x": 670, | |
| "y": 300, | |
| "wires": [] | |
| }, | |
| { | |
| "id": "479fd046.27955", | |
| "type": "function", | |
| "z": "591ff606.f43378", | |
| "name": "'output interval'", | |
| "func": "context.lasttime = context.lasttime || (new Date()).valueOf();\n\nvar now = (new Date()).valueOf();\n\nvar diff = now - context.last;\ncontext.last = now;\n\ncontext.diff = diff;\ncontext.avg = context.avg || diff;\n\ncontext.avg *= 0.995;\ncontext.avg += diff*0.005;\n\ncontext.FPS = 1000/context.diff;\ncontext.FPSavg = 1000/context.avg;\n\nflow.set(\"outputfps\", {fps:context.diff, fpsavg:context.avg});\n\nreturn;", | |
| "outputs": 1, | |
| "noerr": 0, | |
| "x": 800, | |
| "y": 440, | |
| "wires": [ | |
| [] | |
| ] | |
| }, | |
| { | |
| "id": "d580e269.62c2d", | |
| "type": "function", | |
| "z": "591ff606.f43378", | |
| "name": "", | |
| "func": "node.send([msg, null]);\nnode.send([null, msg]);\n", | |
| "outputs": "2", | |
| "noerr": 0, | |
| "x": 110, | |
| "y": 500, | |
| "wires": [ | |
| [ | |
| "94e0bdbd.af10f" | |
| ], | |
| [ | |
| "5e7ed37.c1fb92c" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "9f15a61a.c15828", | |
| "type": "function", | |
| "z": "591ff606.f43378", | |
| "name": "", | |
| "func": "node.send([msg, null]);\nnode.send([null, msg]);\n", | |
| "outputs": "2", | |
| "noerr": 0, | |
| "x": 590, | |
| "y": 460, | |
| "wires": [ | |
| [ | |
| "895994fb.f64a48" | |
| ], | |
| [ | |
| "479fd046.27955" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "4362250e.753b7c", | |
| "type": "function", | |
| "z": "591ff606.f43378", | |
| "name": "'input to encoder interval'", | |
| "func": "context.lasttime = context.lasttime || (new Date()).valueOf();\n\nvar now = (new Date()).valueOf();\n\nvar diff = now - context.last;\ncontext.last = now;\n\ncontext.diff = diff;\ncontext.avg = context.avg || diff;\n\ncontext.avg *= 0.995;\ncontext.avg += diff*0.005;\n\ncontext.FPS = 1000/context.diff;\ncontext.FPSavg = 1000/context.avg;\n\nflow.set(\"output2fps\", {fps:context.diff, fpsavg:context.avg});\n\nreturn;", | |
| "outputs": 1, | |
| "noerr": 0, | |
| "x": 770, | |
| "y": 400, | |
| "wires": [ | |
| [] | |
| ] | |
| }, | |
| { | |
| "id": "512719a6.6a7dd8", | |
| "type": "function", | |
| "z": "591ff606.f43378", | |
| "name": "", | |
| "func": "node.send([msg, null]);\nnode.send([null, msg]);\n", | |
| "outputs": "2", | |
| "noerr": 0, | |
| "x": 570, | |
| "y": 420, | |
| "wires": [ | |
| [ | |
| "4362250e.753b7c" | |
| ], | |
| [ | |
| "9f15a61a.c15828" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "4952fa8d.e82474", | |
| "type": "ui_chart", | |
| "z": "591ff606.f43378", | |
| "name": "", | |
| "group": "885e2c54.00ba2", | |
| "order": 0, | |
| "width": 0, | |
| "height": 0, | |
| "label": "input to encoder frame interval", | |
| "chartType": "line", | |
| "legend": "false", | |
| "xformat": "HH:mm:ss", | |
| "interpolate": "linear", | |
| "nodata": "", | |
| "dot": false, | |
| "ymin": "0", | |
| "ymax": "200", | |
| "removeOlder": 1, | |
| "removeOlderPoints": "100", | |
| "removeOlderUnit": "3600", | |
| "cutout": 0, | |
| "useOneColor": false, | |
| "colors": [ | |
| "#1f77b4", | |
| "#aec7e8", | |
| "#ff7f0e", | |
| "#2ca02c", | |
| "#98df8a", | |
| "#d62728", | |
| "#ff9896", | |
| "#9467bd", | |
| "#c5b0d5" | |
| ], | |
| "useOldStyle": false, | |
| "x": 570, | |
| "y": 660, | |
| "wires": [ | |
| [], | |
| [] | |
| ] | |
| }, | |
| { | |
| "id": "2347704c.93c73", | |
| "type": "function", | |
| "z": "591ff606.f43378", | |
| "name": "GetImage", | |
| "func": "context.framenumber = context.framenumber || 0;\n\nif (msg.payload === 0){\n flow.set('state', 'stop');\n \n // in case we never hit if(stop), delete in 200ms\n // else can't open camera ever again. \n setTimeout(function(){\n var vid = flow.get('cvvid');\n if (vid){\n // stopping, so delete vid whilst we're not using it.\n node.warn(util.inspect(vid));\n vid.release();\n flow.set('cvvid', null);\n delete vid;\n }\n }, 200);\n}\n\n\nif (msg.payload === 1){\n try{\n flow.set('state', 'run');\n\n var cv = flow.get('cv');\n var vid = new cv.VideoCapture(0);\n var fps = vid.setFPS(30);\n node.warn(fps);\n node.warn(vid);\n flow.set('cvvid', vid);\n msg.payload = 'next';\n \n } catch (e){\n node.warn(e);\n }\n \n}\n\nif (msg.payload === 'ack'){\n var timings = flow.get('timings');\n timings.imagecidiff = context.imageci - msg.imageci;\n return;\n}\n\n\nif (msg.payload === 'next'){\n var vid = flow.get('cvvid');\n \n if (vid){\n try{\n //node.warn(\"grabbed \" + util.inspect(err) + \" \"+util.inspect(im));\n vid.read(function(err, im){\n try{\n var state = flow.get(\"state\");\n switch(state){\n case 'stop':\n // stopping, so delete vid whilst we're not using it.\n node.warn(util.inspect(vid));\n vid.release();\n flow.set('cvvid', null);\n delete vid;\n return;\n break;\n default:\n break\n }\n \n if (err) {\n node.warn(\"read \" + util.inspect(err) + \" \"+util.inspect(im));\n return;\n }\n \n if ((im.size()[0] === 0) && (im.size()[1] === 0)){\n node.warn(\"image has zero width or height\");\n return; \n }\n \n msg.payload = im;\n\n node.send([null, {payload:0}, null]);\n\n node.send(msg);\n } catch(e){\n node.warn(e);\n }\n });\n } catch (e){\n node.warn(e);\n }\n }\n}\n", | |
| "outputs": "3", | |
| "noerr": 0, | |
| "x": 420, | |
| "y": 140, | |
| "wires": [ | |
| [ | |
| "edae4349.fa0e6" | |
| ], | |
| [ | |
| "b10830d7.604f" | |
| ], | |
| [] | |
| ] | |
| }, | |
| { | |
| "id": "b10830d7.604f", | |
| "type": "function", | |
| "z": "591ff606.f43378", | |
| "name": "GetNextFrame", | |
| "func": "setTimeout(function(){\n node.send({payload:'next'});\n}, 10);\nreturn;", | |
| "outputs": 1, | |
| "noerr": 0, | |
| "x": 420, | |
| "y": 200, | |
| "wires": [ | |
| [ | |
| "2347704c.93c73" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "c48a2d5d.45a16", | |
| "type": "inject", | |
| "z": "591ff606.f43378", | |
| "name": "Stop", | |
| "topic": "", | |
| "payload": "0", | |
| "payloadType": "num", | |
| "repeat": "", | |
| "crontab": "", | |
| "once": false, | |
| "x": 70, | |
| "y": 140, | |
| "wires": [ | |
| [ | |
| "cdf95ad7.3f5e98" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "edae4349.fa0e6", | |
| "type": "function", | |
| "z": "591ff606.f43378", | |
| "name": "", | |
| "func": "node.send([msg, null]);\nnode.send([null, msg]);\n", | |
| "outputs": "2", | |
| "noerr": 0, | |
| "x": 610, | |
| "y": 80, | |
| "wires": [ | |
| [ | |
| "174dcd7e.c72593" | |
| ], | |
| [ | |
| "40db2c2a.2dcec4" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "40db2c2a.2dcec4", | |
| "type": "function", | |
| "z": "591ff606.f43378", | |
| "name": "", | |
| "func": "node.send([msg, null]);\nnode.send([null, msg]);\n", | |
| "outputs": "2", | |
| "noerr": 0, | |
| "x": 630, | |
| "y": 120, | |
| "wires": [ | |
| [ | |
| "9bef5195.90b0f" | |
| ], | |
| [ | |
| "a98a58d1.04a0a8" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "885e2c54.00ba2", | |
| "type": "ui_group", | |
| "z": "", | |
| "name": "Default", | |
| "tab": "55e1e9cf.f824a8", | |
| "disp": true, | |
| "width": "6" | |
| }, | |
| { | |
| "id": "55e1e9cf.f824a8", | |
| "type": "ui_tab", | |
| "z": "", | |
| "name": "new", | |
| "icon": "dashboard" | |
| } | |
| ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment