發現好像都沒有和大家說過我們完整的專題內容XD
在高端零售(像貴婦超市)中,我們常談「會員制行銷」——但傳統作法仰賴會員卡或手機 App。
我想挑戰一件事:
「讓 AI 看到顧客的臉,就知道他是誰,並推送最懂他的廣告。」
這就是本專題的核心:
人臉識別 × 消費行為 × 生成式廣告
SearchFacesByImage
API 辨識是否為既有會員。使用 Arduino 內建 HTTP POST,每 10 秒拍一張圖上傳至 Flask API:
#include <WiFi.h>
#include <WiFiClient.h>
#include <HTTPClient.h>
void loop() {
camera_fb_t *fb = esp_camera_fb_get();
if (!fb) {
Serial.println("Camera capture failed");
return;
}
WiFiClient client;
HTTPClient http;
http.begin(client, "http://<GCP_VM_IP>:8000/upload_face");
http.addHeader("Content-Type", "image/jpeg");
int res = http.POST(fb->buf, fb->len);
if (res > 0) {
Serial.printf("HTTP Response: %d\n", res);
} else {
Serial.println("Upload failed");
}
http.end();
esp_camera_fb_return(fb);
delay(10000); // 每10秒上傳一次
}
@app.route('/upload_face', methods=['POST'])
def upload_face():
image_bytes = request.data
rekog = boto3.client('rekognition')
result = rekog.search_faces_by_image(
CollectionId='retail-vip',
Image={'Bytes': image_bytes},
MaxFaces=1
)
# 找到 member_id 後查詢資料庫
人臉特徵(FaceEmbedding)儲存在 Rekognition 的私有 Collection 中。
Amazon 會自動以向量形式編碼臉部特徵,開發者只需記錄 ExternalImageId(對應會員編號)。
rekog.index_faces(
CollectionId='retail-vip',
Image={'Bytes': image_bytes},
ExternalImageId='MEM00123ABC',
DetectionAttributes=['DEFAULT']
)
✅ 儲存的是臉部特徵(embedding),不是照片本身,
提升隱私與資料安全性。
難點 | 解決方式 |
---|---|
ESP32-CAM 容量小、易 Brownout | 透過 ESP.restart() 保留穩定上傳循環,並外接 5V 穩壓電源。 |
Rekognition Collection 初始重設 | 啟動 Flask 時偵測 REKOG_RESET=1 環境變數自動重建。 |
辨識精準度 | 設定 QualityFilter="HIGH" 、MaxFaces=1 降低誤判率。 |
上傳延遲 | 影像壓縮為 JPEG (QVGA 320x240) 降低傳輸時間。 |
+-------------+ +--------------------+ +-----------------------+
| ESP32-CAM | -----> | Flask App on GCP | -----> | Amazon Rekognition |
| 拍照上傳 | | 接收影像 & 查DB | | 比對人臉 & 回傳ID |
+-------------+ +--------------------+ +-----------------------+
| |
| v
| Gemini 生成廣告內容
| |
| v
+------------------> Dashboard/廣告螢幕顯示
我們介紹了從攝影機拍照 → 雲端辨識 → 返回會員 ID 的流程。
接下來,Day 21 我會拆解它的「雲端運算成本」與「可商業化設計」,
讓你知道這套系統不但酷,而且便宜得驚人 💰。