• 【opencv.js】Mat 类型对象的创建、复制以及类型转换


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

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

     

    Mat 类型对象的创建

    // 1. 默认构造方式
    let mat = new cv.Mat();
    
    // 2. Create a Mat by size and type
    let mat = new cv.Mat(size, type);
    
    // 3. Create a Mat by rows, cols, and type 
    let mat = new cv.Mat(rows, cols, type)
    
    // 4. Create a Mat by rows, cols, and type with initialization value
    let mat = new cv.Mat(rows, cols, type, new cv.Scalar());
    
    // 5. Create a Mat which is full of zeros
    let mat = cv.Mat.zeros(rows, cols, type);
    
    // 6. Create a Mat which is full of ones
    let mat = cv.Mat.ones(rows, cols, type);
    
    // 7. 对角矩阵
    let mat = cv.Mat.eye(rows, cols, type);
    
    // 8. Use JS array to construct a mat.
    // For example: let mat = cv.matFromArray(2, 2, cv.CV_8UC1, [1, 2, 3, 4]);
    let mat = cv.matFromArray(rows, cols, type, array);
    
    // 9. Use imgData to construct a mat
    let ctx = canvas.getContext("2d");
    let imgData = ctx.getImageData(0, 0, canvas.width, canvas.height);
    let mat = cv.matFromImageData(imgData);

    Mat 类型对象的复制

    // 1. Clone
    let dst = src.clone();
    // 2. CopyTo(only entries indicated in the mask are copied)
    src.copyTo(dst, mask);

     

    Mat 类型对象的类型转换

    src.convertTo(dst, rtype);

     

  • 相关阅读:
    Pytest --快速入门和基础讲解
    Python并发编程(一):多进程(理论篇)
    【面试出题】三数之和
    python 基础:迭代器、生成器
    python垃圾回收机制
    50道Python面试题集锦
    Web自动化测试框架改进
    linux 三剑客
    函数的参数
    生成器
  • 原文地址:https://www.cnblogs.com/bjxqmy/p/12764539.html
Copyright © 2020-2023  润新知