基于ESP32-CAM设计的局域网无线图传功能

  • 4小时前
  • 154

一、前言

1.1 功能介绍

随着物联网技术的飞速发展,无线视频传输在各类智能设备中逐渐成为标准功能。传统的视频监控系统通常依赖有线连接,限制了设备的灵活性和安装位置。在智能家居、遥控小车、扫地机器人等应用场景中,视频流的无线传输显得尤为重要。为了实现这一目标,ESP32-Camera模块作为一种低成本、功能强大的硬件平台,成为了一个理想选择。它不仅具备强大的无线通信能力(Wi-Fi和蓝牙),而且内置摄像头能够进行实时图像采集,广泛应用于遥控小车视频传输、居家监控以及扫地机器人的视频传输等场景。

ESP32-Camera模块的设计非常适合嵌入式视频流传输应用。它的易用性、低功耗和集成化特点,使得用户可以轻松地将其集成到各种设备中,免去复杂的硬件设计和开发。购买该模块后,用户无需编写固件,模块便会自动创建一个Wi-Fi热点,设备连接后通过浏览器即可访问图像捕捉和视频流传输功能,这为开发者提供了极大的便利。在这种预设的固件功能下,用户可以直接使用模块进行简单的图像和视频流显示,无需过多的配置或编程。

为了满足更多灵活的需求,提升用户体验,本项目通过Qt开发设计一个适用于Windows电脑端和Android手机端的上位机应用程序。该应用能够实时获取ESP32-Camera模块的视频流,并显示在设备的界面上。这不仅简化了图像数据的管理和展示,还为用户提供了更友好的操作界面,使得视频流传输过程更加流畅、直观,方便集成到各种实际应用中。

本项目通过无线局域网传输技术,解决传统视频监控系统中有线连接的局限性,并通过智能设备实时显示视频流,进一步提升遥控小车、扫地机器人等智能设备的功能性和互动性。在居家环境中,基于ESP32-Camera的无线视频传输系统能够带来更加便捷的监控解决方案,满足现代家庭对安全、便利和高效的需求。

硬件模块如下:

浏览器访问效果:

手机APP访问效果:

1.2 ESP32-Camera模块

ESP32-Camera模块是一款集成了ESP32微控制器和摄像头的开发板,适用于需要图像捕捉和处理的项目。该模块通常采用OV2640或V3660的CMOS图像传感器,支持分辨率从VGA到较高分辨率的图像捕捉。它能够通过内置的Wi-Fi和蓝牙功能与其他设备进行无线通信,因此特别适用于物联网(IoT)项目中的视频监控、远程监控图像处理和智能安防等应用。

ESP32-Camera模块提供了多个I/O接口,支持GPIOPWMI2CSPI通信协议,这使得它在嵌入式系统中具有很高的灵活性。此外,模块还集成了一个小型的SD卡插槽,用于存储拍摄的图像或视频。它的低功耗特性也使其适用于需要长时间工作的应用场景。

由于ESP32本身具备较强的计算能力和可编程性,ESP32-Camera模块能够进行简单的图像处理任务,如边缘检测、人脸识别等。开发者可以利用ESP32的处理能力直接在设备上执行一些计算任务,减少了对云端计算资源的依赖。

ESP32-Camera模块非常适合于DIY项目和原型开发,它拥有良好的社区支持和丰富的开发资源。开发者可以利用Arduino IDE或ESP-IDF进行开发,并可以使用摄像头模块进行图像捕获、视频流传输等操作。由于其低成本和广泛的兼容性,ESP32-Camera在市场上非常受欢迎,并广泛应用于各种智能家居和物联网设备中。

1.3 功能总结

利用ESP32-Camera模块做一个局域网无线图传功能,用于遥控小车视频传输,扫地机器人视频传输、居家监控等等场景。 ESP32-Camera模块 买回来以后,本身自带固件,不需要编程;上电之后,ESP32-Camera模块就会创建一个名字为ESP32开头的热点,同时在ESP32-CAM内部创建了一个HTTP服务器。手机或者电脑连接上热点以后,打开浏览器,输入IP地址192.168.4.1 就可以看到一个网页。 在网页上可以完成拍照、视频浏览、图像尺寸设置等等。 为了更加灵活使用模块,本项目利用采用Qt开发设计,设计了Windows电脑端、Android手机APP端的上位机,获取显示视频流,实时显示视频,方便集成到项目中。

热点名称:

网页浏览器效果:

1.4 讲解视频

【基于ESP32-CAM实现局域网WIFI图传】

https://www.bilibili.com/video/BV161cDeMED8/?share_source=copy_web&vd_source=347136f3e32fe297fc17177194ce0a8b

1.5 APP下载

我用夸克网盘分享了「基于ESP32-CAM设计的远程摄像头_图传APP.zip」,点击链接即可保存。
链接:https://pan.quark.cn/s/b66c9c876fb5

二、摄像头模块

当前项目设计的时候,购买的模块是这一款【默认有固件,买回来插电就可以使用,不需要烧录代码,不需要编程】。

我当前使用的这款的摄像头是OV3660像素清晰一些,带OV2640摄像头模块是20块钱。

三、代码设计思路

3.1 前提条件

本项目采用Qt5开发,需要安装好QT5开发环境即可。项目当前使用的Qt版本是5.12.6 。

3.2 打开工程

资源包解压之后,将工程工程放在纯英文路径下。 双击打开工程

3.3 选择编译器

第一次打开工程,会让你选择编译器。 看下面:我选择了2个。 一个是Windows电脑的,一个是Android手机的。 如果你的QT环境没有搭建Android环境,那就选择Windows的编译器。 MinGW 即可。

3.4 编译Windows版本

选择左下角的编译器。

再点击绿色三角形。

运行之后,电脑上也要连接ESP32的WIFI热点,连接之后,点击开始播放即可。

然后点击开始播放之后,看到的视频画面。

3.5 编译Android的版本

左下角选择编译器,再进行构建。

构建成功就看到生成的APK文件。可以直接拷贝到Android手机上安装使用。

将APK安装包拷贝到Android手机安装之后。连接ESP32摄像头板子的热点,连接之后,打开手机APP,点击开始播放,就可以在手机上看到图像了。

四、网页代码

这是ESP32-CAM的显示视频流的网页代码,从里面可以了解到如何与服务器交互的流程: 在ESP32-CAM内部是创建了一个HTTP服务器。

<!DOCTYPE html>
<!-- saved from url=(0019)http://192.168.4.1/ -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        
        <meta name="viewport" content="width=device-width,initial-scale=1">
        <title>ESP32 OV3660</title>
        <style>
            body {
                font-family: Arial,Helvetica,sans-serif;
                background: #181818;
                color: #EFEFEF;
                font-size: 16px
            }

            h2 {
                font-size: 18px
            }

            section.main {
                display: flex
            }

            #menu,section.main {
                flex-direction: column
            }

            #menu {
                display: none;
                flex-wrap: nowrap;
                min-width: 340px;
                background: #363636;
                padding: 8px;
                border-radius: 4px;
                margin-top: -10px;
                margin-right: 10px;
            }

            #content {
                display: flex;
                flex-wrap: wrap;
                align-items: stretch
            }

            figure {
                padding: 0px;
                margin: 0;
                -webkit-margin-before: 0;
                margin-block-start: 0;
                -webkit-margin-after: 0;
                margin-block-end: 0;
                -webkit-margin-start: 0;
                margin-inline-start: 0;
                -webkit-margin-end: 0;
                margin-inline-end: 0
            }

            figure img {
                display: block;
                width: 100%;
                height: auto;
                border-radius: 4px;
                margin-top: 8px;
            }

            @media (min-width: 800px) and (orientation:landscape) {
                #content {
                    display:flex;
                    flex-wrap: nowrap;
                    align-items: stretch
                }

                figure img {
                    display: block;
                    max-width: 100%;
                    max-height: calc(100vh - 40px);
                    width: auto;
                    height: auto
                }

                figure {
                    padding: 0 0 0 0px;
                    margin: 0;
                    -webkit-margin-before: 0;
                    margin-block-start: 0;
                    -webkit-margin-after: 0;
                    margin-block-end: 0;
                    -webkit-margin-start: 0;
                    margin-inline-start: 0;
                    -webkit-margin-end: 0;
                    margin-inline-end: 0
                }
            }

            section#buttons {
                display: flex;
                flex-wrap: nowrap;
                justify-content: space-between
            }

            #nav-toggle {
                cursor: pointer;
                display: block
            }

            #nav-toggle-cb {
                outline: 0;
                opacity: 0;
                width: 0;
                height: 0
            }

            #nav-toggle-cb:checked+#menu {
                display: flex
            }

            .input-group {
                display: flex;
                flex-wrap: nowrap;
                line-height: 22px;
                margin: 5px 0
            }

            .input-group>label {
                display: inline-block;
                padding-right: 10px;
                min-width: 47%
            }

            .input-group input,.input-group select {
                flex-grow: 1
            }

            .range-max,.range-min {
                display: inline-block;
                padding: 0 5px
            }

            button {
                display: block;
                margin: 5px;
                padding: 0 12px;
                border: 0;
                line-height: 28px;
                cursor: pointer;
                color: #fff;
                background: #ff3034;
                border-radius: 5px;
                font-size: 16px;
                outline: 0
            }

            button:hover {
                background: #ff494d
            }

            button:active {
                background: #f21c21
            }

            button.disabled {
                cursor: default;
                background: #a0a0a0
            }

            input[type=range] {
                -webkit-appearance: none;
                width: 100%;
                height: 22px;
                background: #363636;
                cursor: pointer;
                margin: 0
            }

            input[type=range]:focus {
                outline: 0
            }

            input[type=range]::-webkit-slider-runnable-track {
                width: 100%;
                height: 2px;
                cursor: pointer;
                background: #EFEFEF;
                border-radius: 0;
                border: 0 solid #EFEFEF
            }

            input[type=range]::-webkit-slider-thumb {
                border: 1px solid rgba(0,0,30,0);
                height: 22px;
                width: 22px;
                border-radius: 50px;
                background: #ff3034;
                cursor: pointer;
                -webkit-appearance: none;
                margin-top: -11.5px
            }

            input[type=range]:focus::-webkit-slider-runnable-track {
                background: #EFEFEF
            }

            input[type=range]::-moz-range-track {
                width: 100%;
                height: 2px;
                cursor: pointer;
                background: #EFEFEF;
                border-radius: 0;
                border: 0 solid #EFEFEF
            }

            input[type=range]::-moz-range-thumb {
                border: 1px solid rgba(0,0,30,0);
                height: 22px;
                width: 22px;
                border-radius: 50px;
                background: #ff3034;
                cursor: pointer
            }

            input[type=range]::-ms-track {
                width: 100%;
                height: 2px;
                cursor: pointer;
                background: 0 0;
                border-color: transparent;
                color: transparent
            }

            input[type=range]::-ms-fill-lower {
                background: #EFEFEF;
                border: 0 solid #EFEFEF;
                border-radius: 0
            }

            input[type=range]::-ms-fill-upper {
                background: #EFEFEF;
                border: 0 solid #EFEFEF;
                border-radius: 0
            }

            input[type=range]::-ms-thumb {
                border: 1px solid rgba(0,0,30,0);
                height: 22px;
                width: 22px;
                border-radius: 50px;
                background: #ff3034;
                cursor: pointer;
                height: 2px
            }

            input[type=range]:focus::-ms-fill-lower {
                background: #EFEFEF
            }

            input[type=range]:focus::-ms-fill-upper {
                background: #363636
            }

            .switch {
                display: block;
                position: relative;
                line-height: 22px;
                font-size: 16px;
                height: 22px
            }

            .switch input {
                outline: 0;
                opacity: 0;
                width: 0;
                height: 0
            }

            .slider {
                width: 50px;
                height: 22px;
                border-radius: 22px;
                cursor: pointer;
                background-color: grey
            }

            .slider,.slider:before {
                display: inline-block;
                transition: .4s
            }

            .slider:before {
                position: relative;
                content: "";
                border-radius: 50%;
                height: 16px;
                width: 16px;
                left: 4px;
                top: 3px;
                background-color: #fff
            }

            input:checked+.slider {
                background-color: #ff3034
            }

            input:checked+.slider:before {
                -webkit-transform: translateX(26px);
                transform: translateX(26px)
            }

            select {
                border: 1px solid #363636;
                font-size: 14px;
                height: 22px;
                outline: 0;
                border-radius: 5px
            }

            .image-container {
                position: relative;
                min-width: 160px
            }

            .close {
                position: absolute;
                right: 5px;
                top: 5px;
                background: #ff3034;
                width: 16px;
                height: 16px;
                border-radius: 100px;
                color: #fff;
                text-align: center;
                line-height: 18px;
                cursor: pointer
            }

            .hidden {
                display: none
            }

            input[type=text] {
                border: 1px solid #363636;
                font-size: 14px;
                height: 20px;
                margin: 1px;
                outline: 0;
                border-radius: 5px
            }

            .inline-button {
                line-height: 20px;
                margin: 2px;
                padding: 1px 4px 2px 4px;
            }

        </style>
    </head>
    <body>
        <section class="main">
            <div id="logo">
                <label for="nav-toggle-cb" id="nav-toggle">☰&nbsp;&nbsp;Toggle OV3660 settings</label>
            </div>
            <div id="content">
                <div id="sidebar">
                    <input type="checkbox" id="nav-toggle-cb" checked="checked">
                    <nav id="menu">
                        <div class="input-group" id="framesize-group">
                            <label for="framesize">Resolution</label>
                            <select id="framesize" class="default-action">
                                <option value="11">QXGA(2048x1564)</option>
                                <option value="10">UXGA(1600x1200)</option>
                                <option value="9">SXGA(1280x1024)</option>
                                <option value="8">XGA(1024x768)</option>
                                <option value="7">SVGA(800x600)</option>
                                <option value="6">VGA(640x480)</option>
                                <option value="5" selected="selected">CIF(400x296)</option>
                                <option value="4">QVGA(320x240)</option>
                                <option value="3">HQVGA(240x176)</option>
                                <option value="0">QQVGA(160x120)</option>
                            </select>
                        </div>
                        <div class="input-group" id="quality-group">
                            <label for="quality">Quality</label>
                            <div class="range-min">4</div>
                            <input type="range" id="quality" min="4" max="63" value="10" class="default-action">
                            <div class="range-max">63</div>
                        </div>
                        <div class="input-group" id="brightness-group">
                            <label for="brightness">Brightness</label>
                            <div class="range-min">-3</div>
                            <input type="range" id="brightness" min="-3" max="3" value="0" class="default-action">
                            <div class="range-max">3</div>
                        </div>
                        <div class="input-group" id="contrast-group">
                            <label for="contrast">Contrast</label>
                            <div class="range-min">-3</div>
                            <input type="range" id="contrast" min="-3" max="3" value="0" class="default-action">
                            <div class="range-max">3</div>
                        </div>
                        <div class="input-group" id="saturation-group">
                            <label for="saturation">Saturation</label>
                            <div class="range-min">-4</div>
                            <input type="range" id="saturation" min="-4" max="4" value="0" class="default-action">
                            <div class="range-max">4</div>
                        </div>
                        <div class="input-group" id="sharpness-group">
                            <label for="sharpness">Sharpness</label>
                            <div class="range-min">-3</div>
                            <input type="range" id="sharpness" min="-3" max="3" value="0" class="default-action">
                            <div class="range-max">3</div>
                        </div>
                        <div class="input-group" id="denoise-group">
                            <label for="denoise">De-Noise</label>
                            <div class="range-min">Auto</div>
                            <input type="range" id="denoise" min="0" max="8" value="0" class="default-action">
                            <div class="range-max">8</div>
                        </div>
                        <div class="input-group" id="ae_level-group">
                            <label for="ae_level">Exposure Level</label>
                            <div class="range-min">-5</div>
                            <input type="range" id="ae_level" min="-5" max="5" value="0" class="default-action">
                            <div class="range-max">5</div>
                        </div>
                        <div class="input-group" id="gainceiling-group">
                            <label for="gainceiling">Gainceiling</label>
                            <div class="range-min">0</div>
                            <input type="range" id="gainceiling" min="0" max="511" value="0" class="default-action">
                            <div class="range-max">511</div>
                        </div>
                        <div class="input-group" id="special_effect-group">
                            <label for="special_effect">Special Effect</label>
                            <select id="special_effect" class="default-action">
                                <option value="0" selected="selected">No Effect</option>
                                <option value="1">Negative</option>
                                <option value="2">Grayscale</option>
                                <option value="3">Red Tint</option>
                                <option value="4">Green Tint</option>
                                <option value="5">Blue Tint</option>
                                <option value="6">Sepia</option>
                            </select>
                        </div>
                        <div class="input-group" id="awb-group">
                            <label for="awb">AWB Enable</label>
                            <div class="switch">
                                <input id="awb" type="checkbox" class="default-action" checked="checked">
                                <label class="slider" for="awb"></label>
                            </div>
                        </div>
                        <div class="input-group" id="dcw-group">
                            <label for="dcw">Advanced AWB</label>
                            <div class="switch">
                                <input id="dcw" type="checkbox" class="default-action" checked="checked">
                                <label class="slider" for="dcw"></label>
                            </div>
                        </div>
                        <div class="input-group" id="awb_gain-group">
                            <label for="awb_gain">Manual AWB</label>
                            <div class="switch">
                                <input id="awb_gain" type="checkbox" class="default-action" checked="checked">
                                <label class="slider" for="awb_gain"></label>
                            </div>
                        </div>
                        <div class="input-group hidden" id="wb_mode-group">
                            <label for="wb_mode">AWB Mode</label>
                            <select id="wb_mode" class="default-action">
                                <option value="0" selected="selected">Auto</option>
                                <option value="1">Sunny</option>
                                <option value="2">Cloudy</option>
                                <option value="3">Office</option>
                                <option value="4">Home</option>
                            </select>
                        </div>
                        <div class="input-group" id="aec-group">
                            <label for="aec">AEC Enable</label>
                            <div class="switch">
                                <input id="aec" type="checkbox" class="default-action" checked="checked">
                                <label class="slider" for="aec"></label>
                            </div>
                        </div>
                        <div class="input-group hidden" id="aec_value-group">
                            <label for="aec_value">Manual Exposure</label>
                            <div class="range-min">0</div>
                            <input type="range" id="aec_value" min="0" max="1536" value="320" class="default-action">
                            <div class="range-max">1536</div>
                        </div>
                        <div class="input-group" id="aec2-group">
                            <label for="aec2">Night Mode</label>
                            <div class="switch">
                                <input id="aec2" type="checkbox" class="default-action" checked="checked">
                                <label class="slider" for="aec2"></label>
                            </div>
                        </div>
                        <div class="input-group" id="agc-group">
                            <label for="agc">AGC</label>
                            <div class="switch">
                                <input id="agc" type="checkbox" class="default-action" checked="checked">
                                <label class="slider" for="agc"></label>
                            </div>
                        </div>
                        <div class="input-group hidden" id="agc_gain-group">
                            <label for="agc_gain">Gain</label>
                            <div class="range-min">1x</div>
                            <input type="range" id="agc_gain" min="0" max="64" value="5" class="default-action">
                            <div class="range-max">64x</div>
                        </div>
                        <div class="input-group" id="raw_gma-group">
                            <label for="raw_gma">GMA Enable</label>
                            <div class="switch">
                                <input id="raw_gma" type="checkbox" class="default-action" checked="checked">
                                <label class="slider" for="raw_gma"></label>
                            </div>
                        </div>
                        <div class="input-group" id="lenc-group">
                            <label for="lenc">Lens Correction</label>
                            <div class="switch">
                                <input id="lenc" type="checkbox" class="default-action" checked="checked">
                                <label class="slider" for="lenc"></label>
                            </div>
                        </div>
                        <div class="input-group" id="hmirror-group">
                            <label for="hmirror">H-Mirror</label>
                            <div class="switch">
                                <input id="hmirror" type="checkbox" class="default-action" checked="checked">
                                <label class="slider" for="hmirror"></label>
                            </div>
                        </div>
                        <div class="input-group" id="vflip-group">
                            <label for="vflip">V-Flip</label>
                            <div class="switch">
                                <input id="vflip" type="checkbox" class="default-action" checked="checked">
                                <label class="slider" for="vflip"></label>
                            </div>
                        </div>
                        <div class="input-group" id="bpc-group">
                            <label for="bpc">BPC</label>
                            <div class="switch">
                                <input id="bpc" type="checkbox" class="default-action">
                                <label class="slider" for="bpc"></label>
                            </div>
                        </div>
                        <div class="input-group" id="wpc-group">
                            <label for="wpc">WPC</label>
                            <div class="switch">
                                <input id="wpc" type="checkbox" class="default-action" checked="checked">
                                <label class="slider" for="wpc"></label>
                            </div>
                        </div>
                        <div class="input-group" id="colorbar-group">
                            <label for="colorbar">Color Bar</label>
                            <div class="switch">
                                <input id="colorbar" type="checkbox" class="default-action">
                                <label class="slider" for="colorbar"></label>
                            </div>
                        </div>
                        <div class="input-group" id="face_detect-group">
                            <label for="face_detect">Face Detection</label>
                            <div class="switch">
                                <input id="face_detect" type="checkbox" class="default-action">
                                <label class="slider" for="face_detect"></label>
                            </div>
                        </div>
                        <div class="input-group" id="face_recognize-group">
                            <label for="face_recognize">Face Recognition</label>
                            <div class="switch">
                                <input id="face_recognize" type="checkbox" class="default-action">
                                <label class="slider" for="face_recognize"></label>
                            </div>
                        </div>
                        <section id="buttons">
                            <button id="get-still">Get Still</button>
                            <button id="toggle-stream">Start Stream</button>
                            <button id="face_enroll" class="disabled" disabled="">Enroll Face</button>
                        </section>
                    </nav>
                </div>
                <figure>
                    <div id="stream-container" class="image-container hidden">
                        <div class="close" id="close-stream">×</div>
                        <img id="stream" src="http://192.168.4.1/">
                    </div>
                </figure>
            </div>
        </section>
        <script>
document.addEventListener('DOMContentLoaded', function (event) 
{
  var baseHost = document.location.origin
  var streamUrl = baseHost + ':81'

  const hide = el => {
    el.classList.add('hidden')
  }
  const show = el => {
    el.classList.remove('hidden')
  }

  const disable = el => {
    el.classList.add('disabled')
    el.disabled = true
  }

  const enable = el => {
    el.classList.remove('disabled')
    el.disabled = false
  }

  const updateValue = (el, value, updateRemote) => {
    updateRemote = updateRemote == null ? true : updateRemote
    let initialValue
    if (el.type === 'checkbox') {
      initialValue = el.checked
      value = !!value
      el.checked = value
    } else {
      initialValue = el.value
      el.value = value
    }

    if (updateRemote && initialValue !== value) {
      updateConfig(el);
    } else if(!updateRemote){
      if(el.id === "aec"){
        value ? hide(exposure) : show(exposure)
      } else if(el.id === "agc"){
        if (value) {
          hide(agcGain)
        } else {
          show(agcGain)
        }
      } else if(el.id === "awb_gain"){
        value ? show(wb) : hide(wb)
      } else if(el.id === "face_recognize"){
        value ? enable(enrollButton) : disable(enrollButton)
      }
    }
  }

  function updateConfig (el) {
    let value
    switch (el.type) {
      case 'checkbox':
        value = el.checked ? 1 : 0
        break
      case 'range':
      case 'select-one':
        value = el.value
        break
      case 'button':
      case 'submit':
        value = '1'
        break
      default:
        return
    }

    const query = `${baseHost}/control?var=${el.id}&val=${value}`

    console.log(`request to ${query}`)
    fetch(query)
      .then(response => {
        console.log(`request to ${query} finished, status: ${response.status}`)
      })
  }

  document
    .querySelectorAll('.close')
    .forEach(el => {
      el.onclick = () => {
        hide(el.parentNode)
      }
    })

  // read initial values
  fetch(`${baseHost}/status`)
    .then(function (response) {
      return response.json()
    })
    .then(function (state) {
      document
        .querySelectorAll('.default-action')
        .forEach(el => {
            updateValue(el, state[el.id], false)
        })
    })

  const view = document.getElementById('stream')
  const viewContainer = document.getElementById('stream-container')
  const stillButton = document.getElementById('get-still')
  const streamButton = document.getElementById('toggle-stream')
  const enrollButton = document.getElementById('face_enroll')
  const closeButton = document.getElementById('close-stream')

  const stopStream = () => {
    window.stop();
    streamButton.innerHTML = 'Start Stream'
  }

  const startStream = () => {
    view.src = `${streamUrl}/stream`
    console.log(`${streamUrl}/stream`)
    show(viewContainer)
    streamButton.innerHTML = 'Stop Stream'
  }

  // Attach actions to buttons
  stillButton.onclick = () => {
    stopStream()
    view.src = `${baseHost}/capture?_cb=${Date.now()}`
    
    console.log(`${baseHost}/capture?_cb=${Date.now()}`)
    show(viewContainer)
  }

  closeButton.onclick = () => {
    stopStream()
    hide(viewContainer)
  }

  streamButton.onclick = () => {
    const streamEnabled = streamButton.innerHTML === 'Stop Stream'
    if (streamEnabled) {
      stopStream()
    } else {
      startStream()
    }
  }

  enrollButton.onclick = () => {
    updateConfig(enrollButton)
  }

  // Attach default on change action
  document
    .querySelectorAll('.default-action')
    .forEach(el => {
      el.onchange = () => updateConfig(el)
    })

  // Custom actions
  // Gain
  const agc = document.getElementById('agc')
  const agcGain = document.getElementById('agc_gain-group')
  agc.onchange = () => {
    updateConfig(agc)
    if (agc.checked) {
      hide(agcGain)
    } else {
      show(agcGain)
    }
  }

  // Exposure
  const aec = document.getElementById('aec')
  const exposure = document.getElementById('aec_value-group')
  aec.onchange = () => {
    updateConfig(aec)
    aec.checked ? hide(exposure) : show(exposure)
  }

  // AWB
  const awb = document.getElementById('awb_gain')
  const wb = document.getElementById('wb_mode-group')
  awb.onchange = () => {
    updateConfig(awb)
    awb.checked ? show(wb) : hide(wb)
  }

  // Detection and framesize
  const detect = document.getElementById('face_detect')
  const recognize = document.getElementById('face_recognize')
  const framesize = document.getElementById('framesize')

  framesize.onchange = () => {
    updateConfig(framesize)
    if (framesize.value > 5) {
      updateValue(detect, false)
      updateValue(recognize, false)
    }
  }

  detect.onchange = () => {
    if (framesize.value > 5) {
      alert("Please select CIF or lower resolution before enabling this feature!");
      updateValue(detect, false)
      return;
    }
    updateConfig(detect)
    if (!detect.checked) {
      disable(enrollButton)
      updateValue(recognize, false)
    }
  } 

  recognize.onchange = () => {
    if (framesize.value > 5) {
      alert("Please select CIF or lower resolution before enabling this feature!");
      updateValue(recognize, false)
      return;
    }
    updateConfig(recognize)
    if (recognize.checked) {
      enable(enrollButton)
      updateValue(detect, true)
    } else {
      disable(enrollButton)
    }
  }
})

        </script>
    

</body></html>

 

人工客服
(售后/吐槽/合作/交友)