Node-REDで画像処理_opencv4nodejs_CODE

30th September 2021 at 7:22am
[
    {
        "id": "c98540bb293ace80",
        "type": "inject",
        "z": "bd33bcab6871647c",
        "name": "初期化",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "topic": "",
        "payloadType": "date",
        "x": 140,
        "y": 80,
        "wires": [
            [
                "304436470ce4770d"
            ]
        ]
    },
    {
        "id": "304436470ce4770d",
        "type": "function",
        "z": "bd33bcab6871647c",
        "name": "Init VideoCapture",
        "func": "const cv = global.get(\"cv\");\n\nconst cap = new cv.VideoCapture(0);\n\nglobal.set(\"cap\", cap);\n\nmsg.payload = \"VideoCaptureの初期化 \";\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 330,
        "y": 80,
        "wires": [
            [
                "de1dae70b6eb899b"
            ]
        ]
    },
    {
        "id": "de1dae70b6eb899b",
        "type": "debug",
        "z": "bd33bcab6871647c",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 530,
        "y": 80,
        "wires": []
    },
    {
        "id": "6551da61e8db9eba",
        "type": "inject",
        "z": "bd33bcab6871647c",
        "name": "実行",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payloadType": "date",
        "x": 150,
        "y": 140,
        "wires": [
            [
                "baeb172d1fd5e141"
            ]
        ]
    },
    {
        "id": "baeb172d1fd5e141",
        "type": "function",
        "z": "bd33bcab6871647c",
        "name": "grab",
        "func": "const cv = global.get(\"cv\");\nconst cap = global.get(\"cap\")\n\nlet image = cap.read();\n//image = image.blur(new cv.Size(3, 3)).canny(30,60);\nconst str =  cv.imencode('.jpg', image).toString('base64');\nmsg.payload = Buffer.from(str, 'base64');\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 290,
        "y": 140,
        "wires": [
            [
                "3245c954feda7937"
            ]
        ]
    },
    {
        "id": "3245c954feda7937",
        "type": "image",
        "z": "bd33bcab6871647c",
        "name": "",
        "width": 160,
        "data": "payload",
        "dataType": "msg",
        "thumbnail": false,
        "active": true,
        "pass": false,
        "outputs": 0,
        "x": 460,
        "y": 140,
        "wires": []
    }
]