LoginSignup
dsvvpxgcseldie
@dsvvpxgcseldie (陽介)

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

Node-REDとLINEの連携のさせ方

Node-REDとLINEの連携のさせ方について

解決したいこと

teachable machineで登録した画像判定をCodePenとNode-REDを連携させ、LINEに判定結果を送付する仕組みを構築したいと思っておりますが、Node-REDとLINE連携のところで、エラー表示が出ており、解決が出来ません。
解決方法を御教授頂きたいと思っております。

現況

1)LINE Developersアカウント登録済(Channel secret、Channel access token発行済)
2)teachable machineで画像判定(マスク着用と不着用)させ、Your shareble linkを発行
3)発行したYour shareble linkをCodePenに取り込み、判定するシステムを構築
4)その内容を一度、Node-REDで受け取って、LINEに送るという事をしたいのですが、Node-REDのfunctionノードの書き方が分からず、現在エラー表示が出ている状況です。
他にも怪しい所がございましたら、解決方法含め、御教授頂けますと幸いです。

発生している問題・エラー

msg.payload : Object
object
judge: "OKです!"
msg : error
"TypeError: Cannot read property 'map' of undefined"

CodePen HTML

<button onclick="start()">開始</button><br>
<video id="webcam" width="320" height="240" muted autoplay playsinline></video>
<p id="result"></p>

CodePen JS

const imageModelURL = 'https://teachablemachine.withgoogle.com/models/hOapgI7kG/';

// メインの関数(ここでは定義しているだけでボタンクリックされたら実行)
async function start() {
  // カメラからの映像ストリーム取得
  const stream = await navigator.mediaDevices.getUserMedia({
    audio: false,
    video: true,
  });

  // 「id="webcam"」となっているパーツ(videoタグ)を取得
  const video = document.getElementById('webcam');

  // videoにカメラ映像ストリームをセット
  video.srcObject = stream;

  // Googleのサーバーにアップロードした自作モデルを読み込みにいきます
  classifier = ml5.imageClassifier(imageModelURL + 'model.json', video, () => {
    // 読み込みが完了次第ここが実行されます
    console.log('モデルの読み込みが完了しました');
  });

  // 繰り返し処理
  function loop() {
    // 推論を実行し、エラーがあればerrに、結果をresultsに格納して、
    // 推論が完了次第 { } の中身を実行します
    classifier.classify(async (err, results) => {
    // 結果のresultsは配列ですが、先頭に中身があれば以下の処理を実行します
    if (results[0]) {
      // 自分の顔の画像を取得
      const myFace = results[0].label;

      // 判定結果を入れる変数を用意
      let judge = '';
      const result = document.getElementById("result");
      // 判定
      if (myFace == 'マスクあり') {
      // マスクあり
        result.style.color = 'green';
        judge = 'OKです!';
      } else {
        // マスクなし
        result.style.color = 'red';
        judge = 'マスクをつけて下さい!';
      }
      // HTML表示に反映
      result.textContent = judge;
      axios.post('https://nodered-egashira.herokuapp.com/receiver', {judge: judge});
    }
    // 推論終了1秒後に自分の関数を実行(ループになる)
    setTimeout(loop, 1000);
  });
  }

  // 最初の繰り返し処理を実行
  loop();
}

Node-REDの構成

image.png

Node-REDの/receiver

image.png
image.png

Node-REDのfunction

image.png

const result = msg.payload.judge;
// 返信したいメッセージの変数を定義しておく
let reply = JSON.stringify(result);
// 返信メッセージをreplyの中身にする
msg.payload = reply;
return msg;

Node-REDのmsg.payload

image.png
image.png

Node-REDのReaply Meassage

image.png
image.png

0

No Answers yet.

Your answer might help someone💌