C# 海康威视平台API接入 和网页摄像头部署

news2024/10/5 20:24:59

文章目录

  • 前言
  • 相关网址
  • 综合安防管理平台
    • 网址
      • 获取Appkey和Secret/密码和密钥
      • 测试
      • 个人魔改工具类
    • 海康视频接入
      • 获取摄像头Id
      • 下载海康Web插件
      • 原生Html导入
        • 网页设置
      • JS封装
        • 封装代码
        • 使用
        • 设置成功!

前言

最近有个需求是将海康的摄像头视频画面传到我们平台上,作为一个全干工程师,网页后端都要我来做。

相关网址

海康开发平台 资源中心

综合安防管理平台

我这里用的是综合安防管理平台
在这里插入图片描述

网址

综合安防管理平台 API

OpenApi 下载

在这里插入图片描述

获取Appkey和Secret/密码和密钥

具体步骤可以看这个

python调用海康视频汇聚平台API,获得所有摄像头设备编号、实时播放rtsp地址、回放rtsp地址

保证有默认合作方

在这里插入图片描述
在这里插入图片描述
拿到Key和Secret

测试

随便找个Api测试

在这里插入图片描述
测试成功,有返回信息就可以了

个人魔改工具类

还是不喜欢全局静态的写法

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Security;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace HaiKang
{
    public class HaiKangService
    {
        /// <summary>
        /// 平台ip
        /// </summary>
        private string _ip;

        /// <summary>
        /// 平台端口
        /// </summary>
        private int _port = 443;

        /// <summary>
        /// 平台APPKey
        /// </summary>
        private string _appkey;

        /// <summary>
        /// 平台APPSecret
        /// </summary>
        private string _secret;

        /// <summary>
        /// 是否使用HTTPS协议
        /// </summary>
        private bool _isHttps = true;
        /// <summary>
        /// 设置信息参数
        /// </summary>
        /// <param name="appkey">合作方APPKey</param>
        /// <param name="secret">合作方APPSecret</param>
        /// <param name="ip">平台IP</param>
        /// <param name="port">平台端口,默认HTTPS的443端口</param>
        /// <param name="isHttps">是否启用HTTPS协议,默认HTTPS</param>
        /// <return></return>
        public HaiKangService()
        {
            _appkey = 你的key;
            _secret = 你的密码;
            _ip = 你的服务器的ip地址;
            _port = 1443;//一般是1443端口
            _isHttps = true;
        }

        /// <summary>
        /// HTTP GET请求
        /// </summary>
        /// <param name="uri">HTTP接口Url,不带协议和端口,如/artemis/api/resource/v1/cameras/indexCode?cameraIndexCode=a10cafaa777c49a5af92c165c95970e0</param>
        /// <param name="timeout">请求超时时间,单位:秒</param>
        /// <returns></returns>
        public (byte[]? bytes, WebResponse? response) HttpGet(string uri, int timeout)
        {
            Dictionary<string, string> header = new Dictionary<string, string>();

            // 初始化请求:组装请求头,设置远程证书自动验证通过
            initRequest(header, uri, "", false);

            // build web request object
            StringBuilder sb = new StringBuilder();
            sb.Append(_isHttps ? "https://" : "http://").Append(_ip).Append(":").Append(_port.ToString()).Append(uri);

            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(sb.ToString());
            req.KeepAlive = false;
            req.ProtocolVersion = HttpVersion.Version11;
            req.AllowAutoRedirect = false;   // 不允许自动重定向
            req.Method = "GET";
            req.Timeout = timeout * 1000;    // 传入是秒,需要转换成毫秒
            req.Accept = header["Accept"];
            req.ContentType = header["Content-Type"];

            foreach (string headerKey in header.Keys)
            {
                if (headerKey.Contains("x-ca-"))
                {
                    req.Headers.Add(headerKey + ":" + header[headerKey]);
                }
            }

            HttpWebResponse rsp = null;
            try
            {
                rsp = (HttpWebResponse)req.GetResponse();
                if (HttpStatusCode.OK == rsp.StatusCode)
                {
                    Stream rspStream = rsp.GetResponseStream();     // 响应内容字节流
                    StreamReader sr = new StreamReader(rspStream);
                    string strStream = sr.ReadToEnd();
                    long streamLength = strStream.Length;
                    byte[] response = System.Text.Encoding.UTF8.GetBytes(strStream);
                    rsp.Close();
                    return ( response,rsp);
                }
                else if (HttpStatusCode.Found == rsp.StatusCode || HttpStatusCode.Moved == rsp.StatusCode)  // 302/301 redirect
                {
                    string reqUrl = rsp.Headers["Location"].ToString();   // 获取重定向URL
                    WebRequest wreq = WebRequest.Create(reqUrl);          // 重定向请求对象
                    WebResponse wrsp = wreq.GetResponse();                // 重定向响应
                    long streamLength = wrsp.ContentLength;               // 重定向响应内容长度
                    Stream rspStream = wrsp.GetResponseStream();          // 响应内容字节流
                    byte[] response = new byte[streamLength];
                    rspStream.Read(response, 0, (int)streamLength);       // 读取响应内容至byte数组
                    rspStream.Close();
                    rsp.Close();
                    return (response, wrsp);
                }

                rsp.Close();
            }
            catch (WebException e)
            {
                if (rsp != null)
                {
                    rsp.Close();
                }
            }

            return (null,null);
        }

        /// <summary>
        /// HTTP Post请求
        /// </summary>
        /// <param name="uri">HTTP接口Url,不带协议和端口,如/artemis/api/resource/v1/org/advance/orgList</param>
        /// <param name="body">请求参数</param>
        /// <param name="timeout">请求超时时间,单位:秒</param>
        /// <return>请求结果</return>
        public (byte[]? bytes, string res_str) HttpPost(string uri, string body, int timeout)
        {
            Dictionary<string, string> header = new Dictionary<string, string>();

            // 初始化请求:组装请求头,设置远程证书自动验证通过
            initRequest(header, uri, body, true);

            // build web request object
            StringBuilder sb = new StringBuilder();
            sb.Append(_isHttps ? "https://" : "http://").Append(_ip).Append(":").Append(_port.ToString()).Append(uri);

            // 创建POST请求
            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(sb.ToString());
            req.KeepAlive = false;
            req.ProtocolVersion = HttpVersion.Version11;
            req.AllowAutoRedirect = false;   // 不允许自动重定向
            req.Method = "POST";
            req.Timeout = timeout * 1000;    // 传入是秒,需要转换成毫秒
            req.Accept = header["Accept"];
            req.ContentType = header["Content-Type"];

            foreach (string headerKey in header.Keys)
            {
                if (headerKey.Contains("x-ca-"))
                {
                    req.Headers.Add(headerKey + ":" + header[headerKey]);
                }
            }

            if (!string.IsNullOrWhiteSpace(body))
            {
                byte[] postBytes = Encoding.UTF8.GetBytes(body);
                req.ContentLength = postBytes.Length;
                Stream reqStream = null;

                try
                {
                    reqStream = req.GetRequestStream();
                    reqStream.Write(postBytes, 0, postBytes.Length);
                    reqStream.Close();
                }
                catch (WebException e)
                {
                    if (reqStream != null)
                    {
                        reqStream.Close();
                    }

                    return (null,null);
                }
            }

            HttpWebResponse rsp = null;
            try
            {
                rsp = (HttpWebResponse)req.GetResponse();
                if (HttpStatusCode.OK == rsp.StatusCode)
                {
                    Stream rspStream = rsp.GetResponseStream();
                    StreamReader sr = new StreamReader(rspStream);
                    string strStream = sr.ReadToEnd();
                    long streamLength = strStream.Length;
                    byte[] response = System.Text.Encoding.UTF8.GetBytes(strStream);
                    rsp.Close();
                    return (response,ResponseToStr(response));
                }
                else if (HttpStatusCode.Found == rsp.StatusCode || HttpStatusCode.Moved == rsp.StatusCode)  // 302/301 redirect
                {
                    try
                    {
                        string reqUrl = rsp.Headers["Location"].ToString();    // 如需要重定向URL,请自行修改接口返回此参数
                        WebRequest wreq = WebRequest.Create(reqUrl);
                        rsp = (HttpWebResponse)wreq.GetResponse();
                        Stream rspStream = rsp.GetResponseStream();
                        long streamLength = rsp.ContentLength;
                        int offset = 0;
                        byte[] response = new byte[streamLength];
                        while (streamLength > 0)
                        {
                            int n = rspStream.Read(response, offset, (int)streamLength);
                            if (0 == n)
                            {
                                break;
                            }

                            offset += n;
                            streamLength -= n;
                        }

                        return ( response, ResponseToStr(response));
                    }
                    catch (Exception e)
                    {
                        return (null,null);
                    }
                }

                rsp.Close();
            }
            catch (WebException e)
            {
                if (rsp != null)
                {
                    rsp.Close();
                }
            }

            return (null,null);
        }

        private void initRequest(Dictionary<string, string> header, string url, string body, bool isPost)
        {
            // Accept                
            string accept = "application/json";// "*/*";
            header.Add("Accept", accept);

            // ContentType  
            string contentType = "application/json";
            header.Add("Content-Type", contentType);

            if (isPost)
            {
                // content-md5,be careful it must be lower case.
                string contentMd5 = computeContentMd5(body);
                header.Add("content-md5", contentMd5);
            }

            // x-ca-timestamp
            string timestamp = ( ( DateTime.Now.Ticks - TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1, 0, 0, 0, 0)).Ticks ) / 1000 ).ToString();
            header.Add("x-ca-timestamp", timestamp);

            // x-ca-nonce
            string nonce = System.Guid.NewGuid().ToString();
            header.Add("x-ca-nonce", nonce);

            // x-ca-key
            header.Add("x-ca-key", _appkey);

            // build string to sign
            string strToSign = buildSignString(isPost ? "POST" : "GET", url, header);
            string signedStr = computeForHMACSHA256(strToSign, _secret);

            // x-ca-signature
            header.Add("x-ca-signature", signedStr);

            if (_isHttps)
            {
                // set remote certificate Validation auto pass
                ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(remoteCertificateValidate);
                ServicePointManager.SecurityProtocol =  SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
            }
        }

        /// <summary>
        /// 计算content-md5
        /// </summary>
        /// <param name="body"></param>
        /// <returns>base64后的content-md5</returns>
        private string computeContentMd5(string body)
        {
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] result = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(body));
            return Convert.ToBase64String(result);
        }

        /// <summary>
        /// 远程证书验证
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="cert"></param>
        /// <param name="chain"></param>
        /// <param name="error"></param>
        /// <returns>验证是否通过,始终通过</returns>
        private bool remoteCertificateValidate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error)
        {
            return true;
        }

        /// <summary>
        /// 计算HMACSHA265
        /// </summary>
        /// <param name="str">待计算字符串</param>
        /// <param name="secret">平台APPSecet</param>
        /// <returns>HMAXH265计算结果字符串</returns>
        private string computeForHMACSHA256(string str, string secret)
        {
            var encoder = new System.Text.UTF8Encoding();
            byte[] secretBytes = encoder.GetBytes(secret);
            byte[] strBytes = encoder.GetBytes(str);
            var opertor = new HMACSHA256(secretBytes);
            byte[] hashbytes = opertor.ComputeHash(strBytes);
            return Convert.ToBase64String(hashbytes);
        }

        /// <summary>
        /// 计算签名字符串
        /// </summary>
        /// <param name="method">HTTP请求方法,如“POST”</param>
        /// <param name="url">接口Url,如/artemis/api/resource/v1/org/advance/orgList</param>
        /// <param name="header">请求头</param>
        /// <returns>签名字符串</returns>
        private string buildSignString(string method, string url, Dictionary<string, string> header)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(method.ToUpper()).Append("\n");
            if (null != header)
            {
                if (null != header["Accept"])
                {
                    sb.Append((string)header["Accept"]);
                    sb.Append("\n");
                }

                if (header.Keys.Contains("Content-MD5") && null != header["Content-MD5"])
                {
                    sb.Append((string)header["Content-MD5"]);
                    sb.Append("\n");
                }

                if (null != header["Content-Type"])
                {
                    sb.Append((string)header["Content-Type"]);
                    sb.Append("\n");
                }

                if (header.Keys.Contains("Date") && null != header["Date"])
                {
                    sb.Append((string)header["Date"]);
                    sb.Append("\n");
                }
            }

            // build and add header to sign
            string signHeader = buildSignHeader(header);
            sb.Append(signHeader);
            sb.Append(url);
            return sb.ToString();
        }

        /// <summary>
        /// 返回字符流
        /// </summary>
        /// <param name="response"></param>
        /// <returns></returns>
        private string ResponseToStr(byte[] bytes)
        {
            var res = "";
            res = System.Text.Encoding.UTF8.GetString(bytes);
            return res;
        }

        /// <summary>
        /// 计算签名头
        /// </summary>
        /// <param name="header">请求头</param>
        /// <returns>签名头</returns>
        private string buildSignHeader(Dictionary<string, string> header)
        {
            Dictionary<string, string> sortedDicHeader = new Dictionary<string, string>();
            sortedDicHeader = header;
            var dic = from objDic in sortedDicHeader orderby objDic.Key ascending select objDic;

            StringBuilder sbSignHeader = new StringBuilder();
            StringBuilder sb = new StringBuilder();
            foreach (KeyValuePair<string, string> kvp in dic)
            {
                if (kvp.Key.Replace(" ", "").Contains("x-ca-"))
                {
                    sb.Append(kvp.Key + ":");
                    if (!string.IsNullOrWhiteSpace(kvp.Value))
                    {
                        sb.Append(kvp.Value);
                    }
                    sb.Append("\n");
                    if (sbSignHeader.Length > 0)
                    {
                        sbSignHeader.Append(",");
                    }
                    sbSignHeader.Append(kvp.Key);
                }
            }

            header.Add("x-ca-signature-headers", sbSignHeader.ToString());

            return sb.ToString();
        }


    }
}

海康视频接入

海康视频接入有两种方式,第一种是有web插件,第二种是无web插件。无web插件弄起来特别的麻烦,所以我们主要讲第一种。

获取摄像头Id

选择分页获取监控点资源
在这里插入图片描述
选择个数多一点
在这里插入图片描述

在这里插入图片描述

下载海康Web插件

海康开发平台下载地址

视频Web 插件 V1.5.2直链下载地址

在这里插入图片描述
下载完成之后我们可以看到Demo,选择合适的自己试一下

在这里插入图片描述

原生Html导入

我这里已经封装好了,我直接拿出来了

网页设置

我将很多无关都隐藏了

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="~/Scripts/jquery-1.12.4.min.js"></script>
    <script src="~/Scripts/jsencrypt.min.js"></script>
    <script src="~/Scripts/web-control_1.2.5.min.js"></script>
	........

</head>
<body>
	.....
     <div id="playWnd" class="playWnd"></div>
</body>
</html>


CSS


.playWnd {
    margin: 30px 0 0 150px;
    width: 1000px; /*播放容器的宽和高设定*/
    height: 600px;
    border: 1px solid red;
}

JS封装

注意,我这个是绑定id的,必须要div的id为playWnd

封装代码


//海康div示例
//<div id = "playWnd" class="playWnd" style = "left: 109px; top: 133px;" ></div >

/**
 * 海康摄像头帮助类
 */
let oWebControl = new WebControl();
class Hik_Class {
    /**
     * 
     * @param {Ip地址} ip
     * @param {端口} port
     * @param {密钥} appkey
     * @param {密码} secret
     * @param {摄像头Id} cameraIndexCode
     */
    constructor(ip, port, appkey, secret, cameraIndexCode) {
        this.ip = ip;
        this.port = port;
        this.appkey = appkey;
        this.secret = secret;
        this.cameraIndexCode = cameraIndexCode
    }

    Init() {
        var that = this
        oWebControl = new WebControl({
            szPluginContainer: "playWnd",                       // 指定容器id
            iServicePortStart: 15900,                           // 指定起止端口号,建议使用该值
            iServicePortEnd: 15900,
            szClassId: "23BF3B0A-2C56-4D97-9C03-0CB103AA8F11",   // 用于IE10使用ActiveX的clsid
            cbConnectSuccess: function () {                     // 创建WebControl实例成功											
                oWebControl.JS_StartService("window", {         // WebControl实例创建成功后需要启动服务
                    dllPath: "./VideoPluginConnect.dll"         // 值"./VideoPluginConnect.dll"写死 
                }).then(function () {                           // 启动插件服务成功
                    oWebControl.JS_SetWindowControlCallback({   // 设置消息回调
                        cbIntegrationCallBack: cbIntegrationCallBack
                    });
                    oWebControl.oDocOffset.top = 95;//设置你的x,y偏移,因为海康插件无法识别多页面的浏览器位置
                    oWebControl.oDocOffset.left = 280;
                    oWebControl.JS_CreateWnd("playWnd", 1000, 600, { bEmbed: true }).then(function () { //JS_CreateWnd创建视频播放窗口,宽高可设定
                        that.init();  // 创建播放实例成功后初始化
                    });
                }, function () { // 启动插件服务失败
                });
            },
            cbConnectError: function () { // 创建WebControl实例失败
                oWebControl = null;
                $("#playWnd").html("插件未启动,正在尝试启动,请稍候...");
                WebControl.JS_WakeUp("VideoWebPlugin://"); // 程序未启动时执行error函数,采用wakeup来启动程序
                initCount++;
                if (initCount < 3) {
                    setTimeout(function () {
                        initPlugin();
                    }, 3000)
                } else {
                    $("#playWnd").html("插件启动失败,请检查插件是否安装!");
                }
            },
            cbConnectClose: function (bNormalClose) {
                // 异常断开:bNormalClose = false
                // JS_Disconnect正常断开:bNormalClose = true	
                console.log("cbConnectClose");
                oWebControl = null;
                $("#playWnd").html("插件未启动,正在尝试启动,请稍候...");
                WebControl.JS_WakeUp("VideoWebPlugin://");
                initCount++;
                if (initCount < 3) {
                    setTimeout(function () {
                        initPlugin();
                    }, 3000)
                } else {
                    $("#playWnd").html("插件启动失败,请检查插件是否安装!");
                }
            }
        });


    }

    init() {
        var that =this
        getPubKey(function () {

            // 请自行修改以下变量值			
            var appkey = that.appkey;                           //综合安防管理平台提供的appkey,必填
            var secret = setEncrypt(that.secret);   //综合安防管理平台提供的secret,必填
            var ip = that.ip;                           //综合安防管理平台IP地址,必填
            var playMode = 0;                                  //初始播放模式:0-预览,1-回放
            var port = that.port;                                    //综合安防管理平台端口,若启用HTTPS协议,默认443
            var snapDir = "D:\\SnapDir";                       //抓图存储路径
            var videoDir = "D:\\VideoDir";                     //紧急录像或录像剪辑存储路径
            var layout = "1x1";                                //playMode指定模式的布局
            var enableHTTPS = 1;                               //是否启用HTTPS协议与综合安防管理平台交互,这里总是填1
            var encryptedFields = 'secret';					   //加密字段,默认加密领域为secret
            var showToolbar = 0;                               //是否显示工具栏,0-不显示,非0-显示
            var showSmart = 0;                                 //是否显示智能信息(如配置移动侦测后画面上的线框),0-不显示,非0-显示
            var buttonIDs = "0,16,256,257,258,259,260,512,513,514,515,516,517,768,769";  //自定义工具条按钮
            // 请自行修改以上变量值	

            oWebControl.JS_RequestInterface({
                funcName: "init",
                argument: JSON.stringify({
                    appkey: appkey,                            //API网关提供的appkey
                    secret: secret,                            //API网关提供的secret
                    ip: ip,                                    //API网关IP地址
                    playMode: playMode,                        //播放模式(决定显示预览还是回放界面)
                    port: port,                                //端口
                    layout: layout,                            //布局
                    enableHTTPS: enableHTTPS,                  //是否启用HTTPS协议
                    encryptedFields: encryptedFields,          //加密字段
                    showToolbar: showToolbar,                  //是否显示工具栏
                    showSmart: showSmart,                      //是否显示智能信息
                    buttonIDs: buttonIDs                       //自定义工具条按钮
                })
            }).then(function (oData) {
                oWebControl.JS_Resize(1000, 600);  // 初始化后resize一次,规避firefox下首次显示窗口后插件窗口未与DIV窗口重合问题
            });
        });
    }

    Connect() {
        console.log("开始连接海康摄像头")
        var cameraIndexCode = this.cameraIndexCode;     //获取输入的监控点编号值,必填
        var streamMode = 0;                                     //主子码流标识:0-主码流,1-子码流
        var transMode = 1;                                      //传输协议:0-UDP,1-TCP
        var gpuMode = 0;                                        //是否启用GPU硬解,0-不启用,1-启用
        var wndId = -1;                                         //播放窗口序号(在2x2以上布局下可指定播放窗口)

        cameraIndexCode = cameraIndexCode.replace(/(^\s*)/g, "");
        cameraIndexCode = cameraIndexCode.replace(/(\s*$)/g, "");

        oWebControl.JS_RequestInterface({
            funcName: "startPreview",
            argument: JSON.stringify({
                cameraIndexCode: cameraIndexCode,                //监控点编号
                streamMode: streamMode,                         //主子码流标识
                transMode: transMode,                           //传输协议
                gpuMode: gpuMode,                               //是否开启GPU硬解
                wndId: wndId                                     //可指定播放窗口
            })
        })
    }

    Close() {
        if (oWebControl != null) {
            oWebControl.JS_HideWnd();   // 先让窗口隐藏,规避可能的插件窗口滞后于浏览器消失问题 
            oWebControl.JS_Disconnect().then(function () {  // 断开与插件服务连接成功
            },
                function () {  // 断开与插件服务连接失败
                });
        }
    }
}

//声明公用变量
var initCount = 0;
var pubKey = '';


// 设置窗口控制回调
function setCallbacks() {
    oWebControl.JS_SetWindowControlCallback({
        cbIntegrationCallBack: cbIntegrationCallBack
    });
}

// 推送消息
function cbIntegrationCallBack(oData) {
    showCBInfo(JSON.stringify(oData.responseMsg));
}



//获取公钥
function getPubKey(callback) {
    oWebControl.JS_RequestInterface({
        funcName: "getRSAPubKey",
        argument: JSON.stringify({
            keyLength: 1024
        })
    }).then(function (oData) {
        console.log(oData);
        if (oData.responseMsg.data) {
            pubKey = oData.responseMsg.data;
            callback()
        }
    })
}

//RSA加密
function setEncrypt(value) {
    var encrypt = new JSEncrypt();
    encrypt.setPublicKey(pubKey);
    return encrypt.encrypt(value);
}

// 监听resize事件,使插件窗口尺寸跟随DIV窗口变化
$(window).resize(function () {
    if (oWebControl != null) {
        oWebControl.JS_Resize(1000, 600);
        setWndCover();
    }
});

// 监听滚动条scroll事件,使插件窗口跟随浏览器滚动而移动
$(window).scroll(function () {
    if (oWebControl != null) {
        oWebControl.JS_Resize(1000, 600);
        setWndCover();
    }
});


// 设置窗口裁剪,当因滚动条滚动导致窗口需要被遮住的情况下需要JS_CuttingPartWindow部分窗口
function setWndCover() {
    var iWidth = $(window).width();
    var iHeight = $(window).height();
    var oDivRect = $("#playWnd").get(0).getBoundingClientRect();

    var iCoverLeft = (oDivRect.left < 0) ? Math.abs(oDivRect.left) : 0;
    var iCoverTop = (oDivRect.top < 0) ? Math.abs(oDivRect.top) : 0;
    var iCoverRight = (oDivRect.right - iWidth > 0) ? Math.round(oDivRect.right - iWidth) : 0;
    var iCoverBottom = (oDivRect.bottom - iHeight > 0) ? Math.round(oDivRect.bottom - iHeight) : 0;

    iCoverLeft = (iCoverLeft > 1000) ? 1000 : iCoverLeft;
    iCoverTop = (iCoverTop > 600) ? 600 : iCoverTop;
    iCoverRight = (iCoverRight > 1000) ? 1000 : iCoverRight;
    iCoverBottom = (iCoverBottom > 600) ? 600 : iCoverBottom;

    oWebControl.JS_RepairPartWindow(0, 0, 1001, 600);    // 多1个像素点防止还原后边界缺失一个像素条
    if (iCoverLeft != 0) {
        oWebControl.JS_CuttingPartWindow(0, 0, iCoverLeft, 600);
    }
    if (iCoverTop != 0) {
        oWebControl.JS_CuttingPartWindow(0, 0, 1001, iCoverTop);    // 多剪掉一个像素条,防止出现剪掉一部分窗口后出现一个像素条
    }
    if (iCoverRight != 0) {
        oWebControl.JS_CuttingPartWindow(1000 - iCoverRight, 0, iCoverRight, 600);
    }
    if (iCoverBottom != 0) {
        oWebControl.JS_CuttingPartWindow(0, 600 - iCoverBottom, 1000, iCoverBottom);
    }
}

//视频预览功能
$("#startPreview").click(function () {

});

//停止全部预览
$("#stopAllPreview").click(function () {
    oWebControl.JS_RequestInterface({
        funcName: "stopAllPreview"
    });
});

// 标签关闭
$(window).unload(function () {
    if (oWebControl != null) {
        oWebControl.JS_HideWnd();   // 先让窗口隐藏,规避可能的插件窗口滞后于浏览器消失问题 
        oWebControl.JS_Disconnect().then(function () {  // 断开与插件服务连接成功
        },
            function () {  // 断开与插件服务连接失败
            });
    }
});





使用
//声明
let hik_Class = new Hik_Class(你的外网ip地址,
 你的端口,
你的AppKey,
你的Secret,
你的摄像头Id)

//使用

hik_Class.Init()//创建窗体
hik_Class.Connect()//连接摄像头并输入视频流
hik_Class.Close()//关闭窗体

设置成功!

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1136831.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

C++简单的栈模型示例

前言 最近在学习C&#xff0c;由于该语言是手动管理内存&#xff0c;所以要对内存池、栈、数组等相关模型要多多了解&#xff0c;下面是一个简单的栈模型。 // dome.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 // #define _CRT_SECURE_NO_WARNIN…

【踩坑记】js用a.push(...b)进行数组组合报栈溢出

建议&#xff1a;进行数组合并时&#xff0c;若不确定数组最终长度或者数组长度超过下述表中数据&#xff0c;建议使用 concat 最近踩了个坑&#xff0c;在进行数组合并时出现了栈溢出的报错。 示例代码&#xff1a; const arr [] for (let i 0; i < 500000; i) {arr.pu…

iOS自动混淆测试处理笔记

1 打开 ipa&#xff0c;导出ipa 路径和配置文件路径会自动填充 2 点击 开始自动混淆测试处理 自动混淆测试是针对 oc 类和oc方法这两个模块进行自动混淆ipa&#xff0c;并ipa安装到设备中运行&#xff0c;通过检测运行ipa包是否崩溃&#xff0c;来对oc类和oc方法进行筛选。如果…

COSCon'23 真·黑客马拉松准备出发!

众多开源爱好者翘首期盼的开源盛会&#xff1a;第八届中国开源年会&#xff08;COSCon23&#xff09;将于 10月28-29日在四川成都市高新区菁蓉汇举办。本次大会的主题是&#xff1a;“开源&#xff1a;川流不息、山海相映”&#xff01;各位新老朋友们&#xff0c;欢迎到成都&a…

【java学习—九】模板方法(TemplateMethod)设计模式(4)

文章目录 1. 在java中什么是模板2. 模板方法设计解决了什么问题&#xff1f;3. 代码化理解 1. 在java中什么是模板 抽象类体现的就是一种模板模式的设计&#xff0c;抽象类作为多个子类的通用模板&#xff0c;子类在抽象类的基础上进行扩展、改造&#xff0c;但子类总体上会保留…

windows安装最新pip官方教程

在执行pip的pip install --upgrade pip更新时&#xff0c;出现如下错误&#xff0c;怎么也无法重新安装&#xff1a; 根据官网的安装教程来 命令的方式一&#xff1a; • 卸载PIP的命令&#xff1a;python -m pip uninstall pip • 重装PIP的命令&#xff1a;python -m ensure…

语雀P0级故障复盘,有9个字亮了

大家好&#xff0c;我是洋子 最近语雀不是出了个号称 “载入史册” 的 P0 级事故嘛 —— 连续宕机接近8个小时无法使用&#xff0c;作为一个大厂知名产品&#xff0c;这个修复速度属实让人无法理解 故障公告原文&#xff1a;https://mp.weixin.qq.com/s/WFLLU8R4bmiqv6OGa-QMc…

【算法设计】贪心算法设计——均分纸牌、线段覆盖问题(C++实现)

创作不易,本篇文章如果帮助到了你,还请点赞 关注支持一下♡>𖥦<)!! 主页专栏有更多知识,如有疑问欢迎大家指正讨论,共同进步! 更多算法分析与设计知识专栏:算法分析🔥 给大家跳段街舞感谢支持!ጿ ኈ ቼ ዽ ጿ ኈ ቼ ዽ ጿ ኈ ቼ ዽ ጿ ኈ ቼ ዽ ጿ ኈ ቼ 目录…

私藏小技巧:让微信朋友圈营销方便化的小窍门!

微信&#xff0c;这个拥有十亿用户的社交软件&#xff0c;已经成为生活中不可或缺的一部分。 而朋友圈&#xff0c;这个微信的基础功能&#xff0c;是聚宝盆&#xff0c;也是一切流量的尽头。 现在公域&#xff0b;私域的流量增长变现体系很火。朋友圈是一切公域流量的尽头&a…

智能硬件适配测试

泽众云测试的智能硬件适配测试&#xff0c;帮助客户解决测试能力和资源问题&#xff0c;提升产品质量、规避产品风险、增加产品竞争力。智能硬件测试通过蓝牙、网络和音频接口等连接方式与手机终端连接&#xff0c;通过兼容性、功能性、连接稳定性、数据同步性测试场景&#xf…

QWEN technical report

通义千问-Qwen技术报告细节分享 - 知乎写在前面大家好&#xff0c;我是刘聪NLP。 阿里在很早前就开源了Qwen-7B模型&#xff0c;但不知道为什么又下架了。就在昨天阿里又开源了Qwen-14B模型&#xff08;原来的7B模型也放出来了&#xff09;&#xff0c;同时还放出了Qwen的技术报…

[CMakeLists]cmake设置堆栈保留大小

MATH(EXPR stack_size "100*1024*1024") set(CMAKE_EXE_LINKER_FLAGS "-Wl,--stack,${stack_size}") 其中100*1024*1024是100MB的大小。 如果是在VS里面写代码则可以按照下图设置&#xff1a;

问题:anaconda的bin和envs目录莫名奇妙消失!

这个命令不是我输入的&#xff0c;在此之后&#xff0c;anaconda的bin目录就找不到了&#xff0c;conda也无法使用&#xff0c;上面命令中的文件也并没有。很奇怪。 为什么为什么为什么&#xff0c;真奇怪。

跨境出口亚马逊美国和加拿大市场水基灭火器UL测试报告审核解析

水基灭火器&#xff08;Foam extinguisher&#xff09;&#xff0c;为绿色外观的灭火器&#xff0c;其灭火器机理为物理性灭火器原理&#xff0c;其主要成分包括碳氢表面活性剂、氟碳表面活性剂、阻燃剂和助剂等。水基灭火器出口需办理UL测试报告。 消防及其他安全用品 本政策…

UE4/UE5 设置widget中text的字体Outline

想要在蓝图中控制Widget 中的 text字体&#xff0c;对字体outline参数进行设置。 但是蓝图中无法直接获取设置outline参数的方法&#xff1a; 没有outline相关的蓝图函数 该参数本身是在Font类别下的扩展&#xff0c;所以只要获取设置Font参数即可进行outline的设置 text连出…

分享一下在微信小程序里怎么添加储值卡功能

在微信小程序中添加储值卡功能&#xff0c;可以让消费者更加便捷地管理和使用储值卡&#xff0c;同时也能增加商家的销售收入。下面是一篇关于如何在微信小程序中添加储值卡功能的软文。 标题&#xff1a;微信小程序添加储值卡功能&#xff0c;便捷与高效并存 随着科技的不断发…

负载均衡策略 LVS

一、集群功能分类 1、LB (1) 概念&#xff1a; LB&#xff1a;负载均衡 (Load Balancing) 是一种分发网络流量的技术&#xff0c;LB 负载均衡的基本原理是将传入的网络流量分发到多个后端服务器&#xff0c;以确保这些服务器都承担相似的工作负载&#xff0c;从而避免某一台…

【CSS】CSS 属性计算过程

1. 概述 我们所书写的任何一个 HTML 元素&#xff0c;实际上都有完整的一整套 CSS 样式。如果没有修改某样式&#xff0c;大概率可能使用默认值。 例如&#xff1a; <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"&…

笔记本Win10系统一键重装系统教程

在Win10笔记本电脑中&#xff0c;用户发现系统出现了崩溃、卡顿等问题&#xff0c;这时候就可以重新安装系统。新安装的系统会更稳定流畅&#xff0c;可以带来更好的操作体验&#xff0c;如果您不知道具体的重装操作步骤&#xff0c;那么就可以参考下面小编分享的笔记本Win10系…

Real- Time Rendering-图形渲染管线(The graphics rendering pipeline)

1、图像渲染管线描述的是什么 图像渲染管线的主要功能是决定在给定虚拟相机&#xff0c;三维物体&#xff0c;光源&#xff0c;照明模式以及纹理等诸多条件的情况下&#xff0c;生成或者绘制一幅二维图像的过程。 渲染图像的位置&#xff0c;形状是由他们的几何形状&#xff0c…