我觉得这是一种廉价并且较为可靠的图像获取方案,目前无法输出视频流,因为我还不知道怎么提升传输速度…
进入正题-- ESP32-CAM模组在某宝上面差不多25块一个(不是M5STACK)我的图像传输方案是先在esp32上面获取图像的16进制字符串,再publish到MQTT服务器上面,接着电脑的客户端把这个hexchar下载下来以后转成2进制,用opencv decode成图像再打开。
ESP32用Arduino IDE编程,电脑上面是用python写的一个小程序来读图像的。
python需要安装opencv。安装方法是在电脑的命令行,或者bash,或者ps里面输入pip install opencv-contrib-python 来安装,推荐把python的pip源换成清华的国内源,这样下载速度会比较快。
#include <Arduino.h>
#include <esp_camera.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include "PubSubClient.h"
#include "CamConfig.h"
WiFiClient Wclient;
PubSubClient client(Wclient);
const char *hostA = "esp32";
const char *ssid = "***********";
const char *password = "***********";
const char *mqtt_server = "************";
boolean shotflag = false;
boolean WiFiDisconnect = false;
String msg;
int timeCount = 0;
void callback(char *topic, byte *message, unsigned int length);
void getimg();
void reconnect();
void setupCamera();
void WiFiEvent(WiFiEvent_t event);
void setup()
{
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
}
Serial.println("WiFi connected");
Serial.println(WiFi.localIP());
WiFi.onEvent(WiFiEvent);
client.setServer(mqtt_server, 1883);
client.setCallback(callback);
setupCamera();
Serial.println("Ready");
}
void loop()
{
reconnect();
client.loop();
if (shotflag == true)
{
getimg();
shotflag = false;
}
}
void getimg()
{
camera_fb_t *fb = esp_camera_fb_get();
// int tranCount = (fb->len * 2 + (1000 - 1)) / 1000;
if (fb)
{
Serial.printf("width: %d, height: %d, buf: 0x%x, le