All Projects → GCY → ESP32-CAM-MJPEG-Stream-Decoder-and-Control-Library

GCY / ESP32-CAM-MJPEG-Stream-Decoder-and-Control-Library

Licence: GPL-3.0 license
The library is MJPEG stream decoder based on libcurl and OpenCV, and written in C/C++.

Programming Languages

c
50402 projects - #5 most used programming language
C++
36643 projects - #6 most used programming language

Projects that are alternatives of or similar to ESP32-CAM-MJPEG-Stream-Decoder-and-Control-Library

Gocv
Go package for computer vision using OpenCV 4 and beyond.
Stars: ✭ 4,511 (+11177.5%)
Mutual labels:  mjpeg, mjpeg-stream, computervision
esp32cam-ready
Plug and Play firmware for the esp32cam. Flash, provision and connect to rtsp.
Stars: ✭ 67 (+67.5%)
Mutual labels:  esp32-arduino, ov2640, esp32-cam
Bmw Yolov4 Training Automation
This repository allows you to get started with training a state-of-the-art Deep Learning model with little to no configuration needed! You provide your labeled dataset or label your dataset using our BMW-LabelTool-Lite and you can start the training right away and monitor it in many different ways like TensorBoard or a custom REST API and GUI. NoCode training with YOLOv4 and YOLOV3 has never been so easy.
Stars: ✭ 533 (+1232.5%)
Mutual labels:  computervision, yolov3
ESP32 I2C Slave
I2C slave library for ESP32
Stars: ✭ 70 (+75%)
Mutual labels:  esp32-arduino, esp32-library
deneyapkart-arduino-core
Arduino Core for Deneyap DevKits
Stars: ✭ 39 (-2.5%)
Mutual labels:  esp32-arduino, ov2640
Learnopencv
Learn OpenCV : C++ and Python Examples
Stars: ✭ 15,385 (+38362.5%)
Mutual labels:  computervision, opencv3
laav
Asynchronous Audio / Video Library for H264 / MJPEG / OPUS / AAC / MP2 encoding, transcoding, recording and streaming from live sources
Stars: ✭ 50 (+25%)
Mutual labels:  mjpeg-stream, mjpeg-decoder
Libtorch Yolov3 Deepsort
Stars: ✭ 165 (+312.5%)
Mutual labels:  wxwidgets, yolov3
ATM90E32
Updated version of the ATM90E32 Arduino library
Stars: ✭ 22 (-45%)
Mutual labels:  esp32-arduino, esp32-library
TTGO-T8-ESP32
esp32-i2s-sdcard-wav-player
Stars: ✭ 89 (+122.5%)
Mutual labels:  esp32-arduino
open62541-arduino
open62541 OPC UA example for Arduino
Stars: ✭ 31 (-22.5%)
Mutual labels:  esp32-arduino
panoramas-image-stitching
🖼 Stitching images into 360 panoramas
Stars: ✭ 155 (+287.5%)
Mutual labels:  opencv3
IBM-Data-Science-Capstone-Alejandra-Marquez
Homemade face mask detector fine-tuning a Yolo-v3 network
Stars: ✭ 28 (-30%)
Mutual labels:  yolov3
YOLO-Streaming
Push-pull streaming and Web display of YOLO series
Stars: ✭ 56 (+40%)
Mutual labels:  yolov3
darknet
php ffi darknet
Stars: ✭ 21 (-47.5%)
Mutual labels:  yolov3
esp-homekit-arduino-sdk
Arduino wrapper for ESP-IDF HomeKit library
Stars: ✭ 34 (-15%)
Mutual labels:  esp32-arduino
Delphi-OpenCV-Class
Experimental Delphi binding for OpenCV 4.XX
Stars: ✭ 34 (-15%)
Mutual labels:  opencv4
ESPAsyncE131
Asynchronous E1.31 (sACN) library for Arduino ESP8266 and ESP32
Stars: ✭ 97 (+142.5%)
Mutual labels:  esp32-arduino
DIoU YOLO V3
📈📈📈【口罩佩戴检测数据训练 | 开源口罩检测数据集和预训练模型】Train D/CIoU_YOLO_V3 by darknet for object detection
Stars: ✭ 53 (+32.5%)
Mutual labels:  yolov3
MIT-Driverless-CV-TrainingInfra
PyTorch pipeline of MIT Driverless Computer Vision paper(2020)
Stars: ✭ 89 (+122.5%)
Mutual labels:  yolov3

ESP32-CAM-MJPEG-Stream-Decoder-and-Control-Library

ESP32-CAM is an inexpensive MJPEG stream embedded device. The library is MJPEG stream decoder based on libcurl and OpenCV, and written in C/C++.

Firmware

Modify the following code in "CameraWebServer.ino" file, that is MJPEG stream boundary.

#define PART_BOUNDARY "WINBONDBOUDARY"
static const char* _STREAM_CONTENT_TYPE = "multipart/x-mixed-replace;boundary=" PART_BOUNDARY;
static const char* _STREAM_BOUNDARY = "\r\n--" PART_BOUNDARY "\r\n";
static const char* _STREAM_PART = "Content-Type: image/jpeg\r\n\r\n";

Easy-to-use

Dependence

  • OpenCV 3 or 4

  • libcurl 7

  • wxWidgets 2.8.12(for wxESP32-CAM example)

Use

Include "ESP32-CAM MJPEG Library" folder into your project.

  • ESP32-CAM Library.h
  • ESP32-CAM Library.cpp
#include "./ESP32-CAM MJPEG Library/ESP32-CAM Library.h"

typedef enum {
    FRAMESIZE_QQVGA,    // 160x120
    FRAMESIZE_QQVGA2,   // 128x160
    FRAMESIZE_QCIF,     // 176x144
    FRAMESIZE_HQVGA,    // 240x176
    FRAMESIZE_QVGA,     // 320x240
    FRAMESIZE_CIF,      // 400x296
    FRAMESIZE_VGA,      // 640x480
    FRAMESIZE_SVGA,     // 800x600
    FRAMESIZE_XGA,      // 1024x768
    FRAMESIZE_SXGA,     // 1280x1024
    FRAMESIZE_UXGA      // 1600x1200
} framesize_t;

ESP32_CAM *esp32_cam = new ESP32_CAM(std::string( "192.168.1.254" ));   //ESP32-CAM local IP address

esp32_cam->SetResolution(FRAMESIZE_SVGA); // Set mjpeg video stream resolution

esp32_cam->StartVideoStream();   // Start mjpeg video stream thread

//cv::Mat frame = esp32_cam->GetFrame(); // Get mjpeg frame
cv::Mat frame; 
esp32_cam >> frame;  // "operator >>" call GetFrame(), like cv::VideoCapture call read() 
if(!frame.empty()){
   cv::imshow("Example",frame);  //Show mjpeg video stream
}

Command POST and ESP32-CAM GET

In cmd_handler, "var" is variable name, "val" is value of variable, curl POST command is:

int ESP32_CAM::SendStream(CURL *curl_object)
{
   long return_code;
   CURLcode response;

   curl_easy_setopt(curl_object,CURLOPT_URL,"192.168.1.254/control?var=framesize&val=7");

   response = curl_easy_perform(curl_object);

   response = curl_easy_getinfo(curl_object, CURLINFO_RESPONSE_CODE, &return_code);

   return (int)return_code;
}

"192.168.1.254/control?var=framesize&val=8", "192.168.1.254" is ESP32-CAM IP address setting from:

// Set your Static IP address
IPAddress local_IP(192, 168, 1, 254);
// Set your Gateway IP address
IPAddress gateway(192, 168, 1, 1);
WiFi.begin(ssid, password);  
WiFi.config(local_IP, gateway, subnet);

In this example, "/control?var=framesize&val=8" POST /control API and set parameter "framesize" value is "7"(FRAMESIZE_SVGA 800x600).

API FlashControl(bool), Flash LED turn on or off "/led?var=flash&val=1", val=1 is on, val=0 is off.

Receive ESP32-CAM Page Content

Set curl_easy_setopt parameter CURLOPT_WRITEFUNCTION and CURLOPT_WRITEDATA for writing received data.

std::string ESP32_CAM::GetRSSI()
{
   std::string buffer;

   curl_easy_setopt(curl_command,CURLOPT_WRITEFUNCTION,WriteCallback);
   curl_easy_setopt(curl_command,CURLOPT_WRITEDATA,&buffer); 

   if(SendStream(curl_command,std::string("/RSSI"))){
   }  

   return buffer;
}

alt text

alt text

MJPEG Stream Format

In this case MJPEG stream boundary is fixed length, for split into a MJPEG stream of JPEG binary(byte), each frame JPEG binary with cv::imdecode decode to RGB format.

const char VIDEO_STREAM_INTERLEAVE[] = "--WINBONDBOUDARY\r\nContent-Type: image/jpeg\r\n\r\n";

const char JPEG_SOI_MARKER_FIRST_BYTE = 0xFF;
const char JPEG_SOI_MARKER_SECOND_BYTE = 0xD8;
Content-type: multipart/x-mixed-replace; boundary=WINBONDBOUDARY

--WINBONDBOUDARY\r\n
Content-Type: image/jpeg\r\n\r\n
JPEG Binary(0xFF,0xD8 ... 0xFF,0xD9)
--WINBONDBOUDARY\r\n 
Content-Type: image/jpeg\r\n\r\n 
JPEG Binary(0xFF,0xD8 ... 0xFF,0xD9) 
...
...
...
--WINBONDBOUDARY\r\n 
Content-Type: image/jpeg\r\n\r\n 
JPEG Binary(0xFF,0xD8 ... 0xFF,0xD9) 

Examples

wxESP32-CAM

Mac OS X or Linux

  • "cd /examples/MAC/wxESP32-CAM/"
  • make

alt text

Windows 10

Build x64 version wxWidgets and libcurl

  • 『x64 Native Tools Command Prompt for VS 2017/2019』, open the program as an administrator.
  • Build x64 libcurl 7.67.0
    • cd "./libcurl-7.67.0/winbuild"
    • run "buildconf.bat"
    • nmake /f Makefile.vc mode=static VC=15 MACHINE=x64 DEBUG=no
    • static link libcurl_a.lib, Ws2_32.lib, Wldap32.lib, winmm.lib, Crypt32.lib, Normaliz.lib
  • Build x64 wxWidgets 3.1.2
    • cd "build/msw"
    • nmake /f makefile.vc /ls RUNTIME_LIBS=static SHARED=0 COMPILER_VERSION=141 TARGET_CPU=X64 BUILD=release
    • nmake /f makefile.vc /ls RUNTIME_LIBS=static SHARED=1 COMPILER_VERSION=141 TARGET_CPU=X64 BUILD=release
  • Build wxESP32-CAM
    • Open *.sln project
    • Select "Release x64"
    • Rebuild

alt text

DNN File

This example is wxWidgets GUI for the library demo, and integrate DNN Computer Vision use cases(YOLO V3, OpenPose).

ESP32-CAM Opencv Example

OpenCV highgui MJPEG stream player.

Mac OS X or Linux

  • cd /examples/MAC/ESP32-CAM Opencv Example/
  • make

alt text

Windows 10

  • Open *.sln project
  • Select "Release x64"
  • Rebuild

alt text

Reference

Pinout Diagram

The following image shows the pinout diagram for the ESP32-CAM AI-Thinker. alt text

Schematic Diagram

The following figure shows the schematic diagram for the ESP32-CAM.

alt text

Licensing

Copyright (C) 2019 TonyGUO https://github.com/GCY.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].