ESP32-S3-CAM视频流捕获到Python实现:WiFi简易指南
目录
1.软硬件准备
2.配置
3.下位机程序
4.上位机程序
1.软硬件准备
ESP32-S3-CAM 淘宝购买板子和烧录座
vscode下载链接Visual Studio Code – Code Editing. Redefined
Arduino IDE Software | Arduino
python Welcome to Python.org
opencv-python OpenCV-python安装教程_opencv python安装-CSDN博客
2.配置
Arduino配置(参考下博客一、二或淘宝商家提供资料)
esp32 cam 从安装、烧录到成为webcam详细教程-CSDN博客
开发板管理器无法下载解决方法解决Arduino IDE无法安装esp32的问题 2024年8月15日更新_arduino下载esp32出错-CSDN博客
对于ESP32-S3-CAM选择开发板
3.下位机程序
直接采用示例程序。
填写自己的wifi和密码。
这里改默认分辨率。
这里是为了提高帧率降低分辨率,根据需求更改。
最后编译上传即可,上传时,按住I00。
上传成功后,按下复位键,运行结果(工具->串口监视器):
4.上位机程序
import cv2
import threading
import requests
from io import BytesIO
from PIL import Image
import numpy as np
ESP32_STREAM_URL = "http://Your Url/stream"
frame = None
lock = threading.Lock()
def fetch_stream():
global frame
try:
stream = requests.get(ESP32_STREAM_URL, stream=True)
byte_stream = BytesIO()
for chunk in stream.iter_content(chunk_size=2048):
byte_stream.write(chunk)
start_index = byte_stream.getvalue().find(b'\xff\xd8')
end_index = byte_stream.getvalue().find(b'\xff\xd9')
if start_index != -1 and end_index != -1:
jpeg_data = byte_stream.getvalue()[start_index:end_index+2]
byte_stream = BytesIO(byte_stream.getvalue()[end_index+2:])
image = Image.open(BytesIO(jpeg_data))
with lock:
frame = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
except Exception as e:
print(f"Error: {e}")
def display_stream():
global frame
while True:
with lock:
if frame is not None:
cv2.imshow("ESP32 Video Stream", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.destroyAllWindows()
if __name__ == "__main__":
fetch_thread = threading.Thread(target=fetch_stream)
fetch_thread.start()
display_stream()
fetch_thread.join()
获得URL的方法(ESP32和PC需要连接相同局域网):
进入串口监视器中的地址
F12进入开发者工具,选择“网络”
点击start stream后,开始捕获图像
鼠标左键单击stream
一般是串口监视器中的地址+":81/stream"
运行python程序
作者:rookiexiaoyu