• 【opencv.js】边界扩展


    JavaScript 写法类似于 C++ 写法。

    相关内容详细介绍请移步官网:【https://docs.opencv.org/3.3.1/de/d06/tutorial_js_basic_ops.html

    代码示例:

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="UTF-8">
        <title>copyBorders</title>
        
        <!--两张图片格式为左浮动,处在一行-->
        <style type="text/css">
            .InputOutput{
                float: left;
                margin: 10px;
            }
        </style>
    </head>
    <body>
        <!--若 opencv.js 文件加载成功,则会显示“opencv.js is ready.”-->
        <p id="status">opencv.js is loading...</p>
        
        <!--图片读入区域-->
        <div class="InputOutput">
            <div class="caption">srcImg<input type="file" id="inputFile" name="file"/></div>
            <img id="srcImg" alt="No Image"/>
        </div>
        
        <!--结果展示区域-->
        <div class="InputOutput">
            <div class="caption">dstImg</div>
            <canvas id="dstImg"></canvas>
        </div>
        
        <!--扩展图片边界,并在 canvas 中显示-->
        <script type="text/javascript">
            <!--读入图片-->
            let imgElement=document.getElementById("srcImg");
            let fileElement=document.getElementById("inputFile");
            fileElement.addEventListener("change",
                    (e) => {imgElement.src = URL.createObjectURL(e.target.files[0]);},
                    false);
            
            <!--扩展边界-->
            imgElement.onload=function(){
                let src=cv.imread(imgElement);
                let dst = new cv.Mat();
                let s = new cv.Scalar(255, 0, 0, 255);
                cv.copyMakeBorder(src, dst, 10, 10, 10, 10, cv.BORDER_CONSTANT, s);
                cv.imshow("dstImg", dst);
                src.delete();
                dst.delete();
            };
            
            <!--成功加载 opencv.js 后,status 标签会显示“opencv.js is ready.”-->
            function onOpenCvReady(){
                document.getElementById("status").innerHTML="opencv.js is ready.";
            }
        </script>
        <script async src="opencvjs/opencv.js" onload="onOpenCvReady();" type="text/javascript"></script>
    </body>
    </html>

    效果演示:

  • 相关阅读:
    tomcat的安装及配置
    java动态代理的实现
    mySql单列索引与联合索引的区别
    maven3.5.0在win10中的安装及环境变量配置
    jQuery相关知识总结
    前端-css
    前段篇:HTML
    Mysql基础安装,初视篇
    论事件驱动与异步IO
    python 之协程
  • 原文地址:https://www.cnblogs.com/bjxqmy/p/12765272.html
Copyright © 2020-2023  润新知