AIカメラの写真の内容をCUI上で確認する

© CC BY 4+ visibility255
© CC BY 4+
visibility255

M5 UNITV2などのAIカメラで写真を撮ったあと、何の写真かわからなくなってしまった場合のライフハックです。CUIからでもわかりますが、Slackにも説明文を飛ばして写真の内容を確認します。

link https://youtube.com/shorts/Ydpz7vjQVzI?si=aDgYVBz_3OTSozqy
動画
開発素材
システム構成

今回はM5STACK UnitV2を使いました。

まずはファームウェアアップデートをします。 https://docs.m5stack.com/en/guide/ai_camera/unitv2/update

その後wifi設定をしていきます。SSIDとパスワードを sudo nano /etc/wpa_supplicant.conf コマンドにて修正 し、再起動します。 https://docs.m5stack.com/en/guide/ai_camera/unitv2/config

デフォルトから下記ライブラリをインストールします。

openai バージョン1.35.7

sudo pip3 install openai==1.35.7

コードは下記です。

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

import base64

from openai import OpenAI import requests import json

SLACK_URL = "slackのwebhookURLを張り付けてください"

def encode_image(image_path): with open(image_path, "rb") as image_file: return base64.b64encode(image_file.read()).decode("utf-8")

image_path = "./test.jpg"

base64_image = encode_image(image_path)

client = OpenAI( api_key="openAIのapiキーを入力してください", )

response = client.chat.completions.create( # model の名前は gpt-4-vision-preview. model="gpt-4-vision-preview", messages=[ { "role": "user", "content": [ {"type": "text", "text": "何の画像?"},
{"type": "image_url", "image_url": f"data:image/jpeg;base64,{base64_image}"},
], } ], max_tokens=300, ) def send_slack(): content = str(response.choices[0]) payload = { "text": content, "icon_emoji": ':snake:', } data = json.dumps(payload) requests.post(SLACK_URL, data) send_slack()

print(response.choices[0])

”””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””

コードのなかで2つ外部APIを叩いています。 ひとつはopenaiです。 下記を参照にAPIキーをコードに埋め込んでください。 https://setsubi.no-mania.com/ SlackのwebhookURLの取得は下記にて取得してください。 https://qiita.com/bakira/items/8fa06ab10edf1f42ff97

slackアプリをインストールしていればスマホでも確認することができます。

ストーリー

AIカメラは単体では画像が確認できません。SSHなどでログインしなければならないのですが、それでも画像の確認は難しいです。今回はUNITV2を使って画像をAIプラットフォームへ送り、画像を解析しました。今後はAIカメラに学習データなどがデフォルトで入っていればCUI上でもどんなファイルなのか確認できる日が来るかもしれませんね…。

Images cannot be confirmed with the AI ​​camera alone. I have to log in using SSH etc., but it is still difficult to check the images. This time, we used UNITV2 to send images to the AI ​​platform and analyze the images. In the future, if learning data is included in the AI ​​camera by default, the day may come when you can check what kind of file it is on the CUI...

メンバー
  • user
    ultimatemasahi @ultimatemasahi

関連イベント
  • event M5Stack Japan Creativity Contest 20242024-06-01 開催

同じニオイがする作品
  • event せんべろタクシー
  • event Draw Shop
  • event ぺパ子のファッションチェック
  • event 巷で流行りのChatGPTで邪神ちゃんエーアイ!を作りましたの

イベントまとめ

コンテストまとめ

作品を登録しよう

モノづくりしている人に、つくった作品を見てもらえ、リアクションがもらえるかも?

close

目次