国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

ESP32-CAM網(wǎng)絡(luò)攝像頭系列-01-基于RTSP協(xié)議的局域網(wǎng)視頻推流/拉流的簡單實現(xiàn)

這篇具有很好參考價值的文章主要介紹了ESP32-CAM網(wǎng)絡(luò)攝像頭系列-01-基于RTSP協(xié)議的局域網(wǎng)視頻推流/拉流的簡單實現(xiàn)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

前言:

????????由于項目需要,最近開始開坑關(guān)于ESP32-CAM系列的RTSP網(wǎng)絡(luò)攝像頭系列,該文章為該系列的第一篇文章。用于記錄項目開發(fā)過程。

本文解決的問題:

? ? ? ? 使用ESP32-CAM獲取圖像數(shù)據(jù),并通過RTSP協(xié)議將獲取到的視頻流傳輸?shù)缴衔粰C進行顯示。

具體實現(xiàn):

????????使用ESP32-CAM進行視頻推流,python端作為rtsp拉流,其中ESP32-CAM使用arduinoIDE開發(fā),使用了安信可的支持庫。支持包安裝網(wǎng)址:

拉流效果:

ESP32-CAM網(wǎng)絡(luò)攝像頭系列-01-基于RTSP協(xié)議的局域網(wǎng)視頻推流/拉流的簡單實現(xiàn)

一、推流部分

官方示例代碼:

#include "OV2640.h"
#include <WiFi.h>
#include <WebServer.h>
#include <WiFiClient.h>

#include "SimStreamer.h"
#include "OV2640Streamer.h"
#include "CRtspSession.h"

#define ENABLE_RTSPSERVER

OV2640 cam;

#ifdef ENABLE_WEBSERVER
WebServer server(80);
#endif

#ifdef ENABLE_RTSPSERVER
WiFiServer rtspServer(8554);
#endif


#ifdef SOFTAP_MODE
IPAddress apIP = IPAddress(192, 168, 1, 1);
#else
#include "wifikeys_template.h"
#endif

#ifdef ENABLE_WEBSERVER
void handle_jpg_stream(void)
{
    WiFiClient client = server.client();
    String response = "HTTP/1.1 200 OK\r\n";
    response += "Content-Type: multipart/x-mixed-replace; boundary=frame\r\n\r\n";
    server.sendContent(response);

    while (1)
    {
        cam.run();
        if (!client.connected())
            break;
        response = "--frame\r\n";
        response += "Content-Type: image/jpeg\r\n\r\n";
        server.sendContent(response);

        client.write((char *)cam.getfb(), cam.getSize());
        server.sendContent("\r\n");
        if (!client.connected())
            break;
    }
}

void handle_jpg(void)
{
    WiFiClient client = server.client();

    cam.run();
    if (!client.connected())
    {
        return;
    }
    String response = "HTTP/1.1 200 OK\r\n";
    response += "Content-disposition: inline; filename=capture.jpg\r\n";
    response += "Content-type: image/jpeg\r\n\r\n";
    server.sendContent(response);
    client.write((char *)cam.getfb(), cam.getSize());
}

void handleNotFound()
{
    String message = "Server is running!\n\n";
    message += "URI: ";
    message += server.uri();
    message += "\nMethod: ";
    message += (server.method() == HTTP_GET) ? "GET" : "POST";
    message += "\nArguments: ";
    message += server.args();
    message += "\n";
    server.send(200, "text/plain", message);
}
#endif

#ifdef ENABLE_OLED
#define LCD_MESSAGE(msg) lcdMessage(msg)
#else
#define LCD_MESSAGE(msg)
#endif

#ifdef ENABLE_OLED
void lcdMessage(String msg)
{
    if(hasDisplay) {
        display.clear();
        display.drawString(128 / 2, 32 / 2, msg);
        display.display();
    }
}
#endif

CStreamer *streamer;

void setup()
{
  #ifdef ENABLE_OLED
    hasDisplay = display.init();
    if(hasDisplay) {
        display.flipScreenVertically();
        display.setFont(ArialMT_Plain_16);
        display.setTextAlignment(TEXT_ALIGN_CENTER);
    }
  #endif
    LCD_MESSAGE("booting");

    Serial.begin(115200);
    while (!Serial)
    {
        ;
    }
    cam.init(esp32cam_aithinker_config);

    IPAddress ip;


#ifdef SOFTAP_MODE
    const char *hostname = "devcam";
    // WiFi.hostname(hostname); // FIXME - find out why undefined
    LCD_MESSAGE("starting softAP");
    WiFi.mode(WIFI_AP);
    WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
    bool result = WiFi.softAP(hostname, "12345678", 1, 0);
    if (!result)
    {
        Serial.println("AP Config failed.");
        return;
    }
    else
    {
        Serial.println("AP Config Success.");
        Serial.print("AP MAC: ");
        Serial.println(WiFi.softAPmacAddress());

        ip = WiFi.softAPIP();
    }
#else
    LCD_MESSAGE(String("join ") + ssid);
    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED)
    {
        delay(500);
        Serial.print(F("."));
    }
    ip = WiFi.localIP();
    Serial.println(F("WiFi connected"));
    Serial.println("");
    Serial.println(ip);
#endif

    LCD_MESSAGE(ip.toString());

#ifdef ENABLE_WEBSERVER
    server.on("/", HTTP_GET, handle_jpg_stream);
    server.on("/jpg", HTTP_GET, handle_jpg);
    server.onNotFound(handleNotFound);
    server.begin();
#endif

#ifdef ENABLE_RTSPSERVER
    rtspServer.begin();

    //streamer = new SimStreamer(true);             // our streamer for UDP/TCP based RTP transport
    streamer = new OV2640Streamer(cam);             // our streamer for UDP/TCP based RTP transport
#endif
}

void loop()
{
#ifdef ENABLE_WEBSERVER
    server.handleClient();
#endif

#ifdef ENABLE_RTSPSERVER
    uint32_t msecPerFrame = 100;
    static uint32_t lastimage = millis();

    // If we have an active client connection, just service that until gone
    streamer->handleRequests(0); // we don't use a timeout here,
    // instead we send only if we have new enough frames
    uint32_t now = millis();
    if(streamer->anySessions()) {
        if(now > lastimage + msecPerFrame || now < lastimage) { // handle clock rollover
            streamer->streamImage(now);
            lastimage = now;

            // check if we are overrunning our max frame rate
            now = millis();
            if(now > lastimage + msecPerFrame) {
                printf("warning exceeding max frame rate of %d ms\n", now - lastimage);
            }
        }
    }
    
    WiFiClient rtspClient = rtspServer.accept();
    if(rtspClient) {
        Serial.print("client: ");
        Serial.print(rtspClient.remoteIP());
        Serial.println();
        streamer->addSession(rtspClient);
    }
#endif
}

????????對于ESP32的RTSP推流安信可官方已經(jīng)給出了相應(yīng)的示例代碼,改代碼使用宏定義的方式區(qū)分http和rtsp協(xié)議的不同代碼。由于我們不需要用到基于http協(xié)議的視頻推流,因此可以刪去官方代碼中不必要的部分。修改完的代碼如下:

ESP32部分的代碼由官方示例代碼修改而來。只保留RTSP推流部分。

#include "OV2640.h"
#include <WiFi.h>
#include <WebServer.h>
#include <WiFiClient.h>

#include "SimStreamer.h"
#include "OV2640Streamer.h"
#include "CRtspSession.h"

// copy this file to wifikeys.h and edit
const char *ssid =     "YAN";         // Put your SSID here
const char *password = "qwertyuiop";     // Put your PASSWORD here

#define ENABLE_RTSPSERVER

OV2640 cam;

WiFiServer rtspServer(8554);

CStreamer *streamer;

void setup()
{
    Serial.begin(115200);
    while (!Serial);
    cam.init(esp32cam_aithinker_config);

    IPAddress ip;

    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED)
    {
        delay(500);
        Serial.print(F("."));
    }
    ip = WiFi.localIP();
    Serial.println(F("WiFi connected"));
    Serial.println("");
    Serial.println(ip);

    rtspServer.begin();

    //streamer = new SimStreamer(true);             // our streamer for UDP/TCP based RTP transport
    streamer = new OV2640Streamer(cam);             // our streamer for UDP/TCP based RTP transport
}

void loop()
{
    uint32_t msecPerFrame = 100;
    static uint32_t lastimage = millis();

    // If we have an active client connection, just service that until gone
    streamer->handleRequests(0); // we don't use a timeout here,
    // instead we send only if we have new enough frames
    uint32_t now = millis();
    if(streamer->anySessions()) {
        if(now > lastimage + msecPerFrame || now < lastimage) { // handle clock rollover
            streamer->streamImage(now);
            lastimage = now;

            // check if we are overrunning our max frame rate
            now = millis();
            if(now > lastimage + msecPerFrame) {
                printf("warning exceeding max frame rate of %d ms\n", now - lastimage);
            }
        }
    }
    
    WiFiClient rtspClient = rtspServer.accept();
    if(rtspClient) {
        Serial.print("client: ");
        Serial.print(rtspClient.remoteIP());
        Serial.println();
        streamer->addSession(rtspClient);
    }
}

ArduinoIDE串口監(jiān)視器輸出的初始化信息,我們需要將ESP32的IP地址安裝RTSP協(xié)議推流的格式填入Python拉流代碼中。

# RTSP 地址
rtsp_url = "rtsp://192.168.168.238:8554/mjpeg/2"

ESP32-CAM網(wǎng)絡(luò)攝像頭系列-01-基于RTSP協(xié)議的局域網(wǎng)視頻推流/拉流的簡單實現(xiàn)

?二、拉流部分

? ? ? ? 由于Opencv-python集成了RTSP協(xié)議拉流的庫函數(shù),因此我們需要下載Opencv-python的支持包??梢源蜷_Pycharm的Terminal使用pip指令快速下載。

pip install opencv-python

?上位機python3拉流代碼:

import cv2

# RTSP 地址
rtsp_url = "rtsp://192.168.168.238:8554/mjpeg/2"

# 打開 RTSP 視頻流
cap = cv2.VideoCapture(rtsp_url)

# 檢查視頻是否成功打開
if not cap.isOpened():
    print("Failed to open RTSP stream")
    exit()

# 循環(huán)讀取視頻幀
while True:
    # 讀取視頻幀
    ret, frame = cap.read()

    # 檢查是否成功讀取視頻幀
    if not ret:
        break

    # 顯示視頻幀
    cv2.imshow("RTSP Stream", frame)

    # 按 'q' 鍵退出循環(huán)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# 釋放資源
cap.release()
cv2.destroyAllWindows()

PS:需要注意的是,進行RTSP拉流的上位機和推流的下位機都需要位于同一個局域網(wǎng)下才能進行推拉流傳輸。文章來源地址http://www.zghlxwxcb.cn/news/detail-512352.html

到了這里,關(guān)于ESP32-CAM網(wǎng)絡(luò)攝像頭系列-01-基于RTSP協(xié)議的局域網(wǎng)視頻推流/拉流的簡單實現(xiàn)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • 【ESP32-CAM】20元就能搭建簡易Web攝像頭

    【ESP32-CAM】20元就能搭建簡易Web攝像頭

    在首選項中,增加網(wǎng)址https://dl.espressif.com/dl/package_esp32_index.json 安裝esp32資源包 選擇ESP32-CAM開發(fā)板 選一個USB-TTL的串口工具,按照圖示,RX接U0TXD,TX接U0RXD,GND和5V供電,其中GPIO0在燒錄時需要短接到GND 在IDE上選擇串口,可以取得開發(fā)板信息測試一下 在示例中選擇WebServer 默認(rèn)不

    2024年02月13日
    瀏覽(25)
  • ubuntu利用usb_cam打開攝像頭

    ubuntu利用usb_cam打開攝像頭

    想要標(biāo)定多個相機,首先得把相機打開吧,usb_cam是針對usb攝像頭的ros驅(qū)動包,簡單來說就是得有這個功能包,才能在ros中把攝像頭打開。 首先打開終端,輸入: 這里melodic應(yīng)該根據(jù)自己Ubuntu系統(tǒng)進行靈活變換,例如我使用的Ubuntu18.04,那么我對應(yīng)的就是melodic版本。 驅(qū)動安裝

    2024年02月03日
    瀏覽(26)
  • 【完全開源】小安派-Cam-D200(AiPi-Cam-D200)200W攝像頭開發(fā)板

    【完全開源】小安派-Cam-D200(AiPi-Cam-D200)200W攝像頭開發(fā)板

    AiPi-Cam-D200 是安信可科技基于AiPi-Cam-D開發(fā)板 開發(fā)的一款兼容200W 攝像頭的開發(fā)板,相當(dāng)于給AiPi-Cam-D 做了升級迭代。 攝像頭型號:GC2145 攝像頭尺寸:13*13*21.57 mm(長 寬 高,不含排線) 像素大小:1600*1200 視角:140° 焦距:2米 功耗:180mA(200uA) 接口:DVP(24Pin間距0.5mm) IO名稱 功能

    2024年02月19日
    瀏覽(79)
  • 基于??礢DK實現(xiàn)Python調(diào)用??低暰W(wǎng)絡(luò)攝像頭

    基于海康SDK實現(xiàn)Python調(diào)用??低暰W(wǎng)絡(luò)攝像頭

    本文參考博客,寫得很好: Python調(diào)用??低暰W(wǎng)絡(luò)相機之——python調(diào)用??低旵++的SDK Python調(diào)用海康威視網(wǎng)絡(luò)相機C++的SDK 寫本文的目的,也是快速復(fù)盤,所以沒有很詳細(xì) 保存視頻流到本地可參考下一篇:基于??礢DK實現(xiàn)Python保存海康威視網(wǎng)絡(luò)攝像頭拍攝的視頻 Windows11 Vis

    2024年02月02日
    瀏覽(54)
  • 基于TCP/IP協(xié)議的網(wǎng)絡(luò)攝像頭的QT項目

    基于TCP/IP協(xié)議的網(wǎng)絡(luò)攝像頭的QT項目

    目錄 項目簡述: 1.服務(wù)器 ?步驟一:首先搭建一個基本的服務(wù)器框架。 ?1.初始化服務(wù)器的函數(shù)主體 ?2.等待連接 步驟二:數(shù)據(jù)庫的使用,本次項目使用的Sqlite3數(shù)據(jù)庫 1.數(shù)據(jù)庫初始化 2.登錄時使用數(shù)據(jù)庫? 3.注冊時使用數(shù)據(jù)庫 步驟三:攝像頭的調(diào)用與數(shù)據(jù)傳輸 1.V4L2框架的使

    2024年02月03日
    瀏覽(28)
  • 33、基于STM32單片機車牌識別系統(tǒng)攝像頭圖像處理系統(tǒng)設(shè)計

    33、基于STM32單片機車牌識別系統(tǒng)攝像頭圖像處理系統(tǒng)設(shè)計

    畢設(shè)幫助、開題指導(dǎo)、技術(shù)解答(有償)見文末。 目錄 摘要 一、硬件方案 二、設(shè)計功能 三、實物圖 四、原理圖 五、PCB圖 六、程序源碼 七、資料包括 隨著汽車工業(yè)的迅猛發(fā)展,我國汽車擁有量急劇增加。停車場作為交通設(shè)施的組成部分,隨著交通運輸?shù)姆泵筒粩喟l(fā)展,

    2024年02月15日
    瀏覽(32)
  • 學(xué)習(xí)筆記:利用usb_cam進行單目標(biāo)定與畸變矯正(筆記本攝像頭 or usb相機)

    學(xué)習(xí)筆記:利用usb_cam進行單目標(biāo)定與畸變矯正(筆記本攝像頭 or usb相機)

    一個剛?cè)腴T視覺的學(xué)習(xí)筆記,怕哪天系統(tǒng)崩了找不回筆記了,故上傳到博客方便保留。 1、準(zhǔn)備工作(安裝usb_cam) 1)創(chuàng)建文件夾 2)下載編譯安裝usb_cam包(該包能將攝像頭的圖像通過sensor_msgs::Image消息發(fā)布) ? ?2、可以通過ls/dev/video*來查看電腦的設(shè)備號來選擇外接或筆記本

    2024年02月07日
    瀏覽(26)
  • 實時人臉檢測:基于卷積神經(jīng)網(wǎng)絡(luò)CNN和OpenCV的攝像頭應(yīng)用

    人臉檢測是計算機視覺中的重要任務(wù)之一,廣泛應(yīng)用于人臉識別、人臉表情分析、人臉跟蹤等領(lǐng)域。在實時視頻流中進行人臉檢測可以幫助我們快速準(zhǔn)確地識別和定位圖像中的人臉。本文將介紹如何使用 OpenCV 庫來實現(xiàn)通過本地攝像頭獲取實時視頻流,并利用預(yù)訓(xùn)練的深度學(xué)

    2024年02月07日
    瀏覽(22)
  • ROS高效進階第四章 -- 機器視覺處理之圖像格式,usb_cam,攝像頭標(biāo)定,opencv和cv_bridge引入

    ROS高效進階第四章 -- 機器視覺處理之圖像格式,usb_cam,攝像頭標(biāo)定,opencv和cv_bridge引入

    從本文開始,我們用四篇文章學(xué)習(xí)ROS機器視覺處理,本文先學(xué)習(xí)一些外圍的知識,為后面的人臉識別,目標(biāo)跟蹤和yolov5目標(biāo)檢測做準(zhǔn)備。 我的筆記本是Thinkpad T14 i7 + Nvidia MX450,系統(tǒng)是ubuntu20.04,ros是noetic。由于很多驅(qū)動與硬件強相關(guān),請讀者注意這點。 本文的參考資料有:

    2024年02月04日
    瀏覽(25)
  • 76、基于STM32單片機車牌識別攝像頭圖像處理掃描設(shè)計(程序+原理圖+PCB源文件+相關(guān)資料+參考PPT+元器件清單等)

    76、基于STM32單片機車牌識別攝像頭圖像處理掃描設(shè)計(程序+原理圖+PCB源文件+相關(guān)資料+參考PPT+元器件清單等)

    單片機主芯片選擇方案 方案一:AT89C51是美國ATMEL公司生產(chǎn)的低電壓,高性能CMOS型8位單片機,器件采用ATMEL公司的高密度、非易失性存儲技術(shù)生產(chǎn),兼容標(biāo)準(zhǔn)MCS-51指令系統(tǒng),片內(nèi)置通用8位中央處理器(CPU)和Flash存儲單元,功能強大。其片內(nèi)的4K程序存儲器是FLASH工藝的,這種單

    2024年02月12日
    瀏覽(18)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包