zoukankan      html  css  js  c++  java
  • Mat::operator =

    Provides matrix assignment operators.

    C++: Mat& Mat::operator=(const Mat& m)
    C++: Mat& Mat::operator=(const MatExpr& expr)
    C++: Mat& Mat::operator=(const Scalar& s)
    Parameters:
    • m – Assigned, right-hand-side matrix. Matrix assignment is an O(1) operation. This means that no data is copied but the data is shared and the reference counter, if any, is incremented. Before assigning new data, the old data is de-referenced via Mat::release() .
    • expr – Assigned matrix expression object. As opposite to the first form of the assignment operation, the second form can reuse already allocated matrix if it has the right size and type to fit the matrix expression result. It is automatically handled by the real function that the matrix expressions is expanded to. For example, C=A+B is expanded to add(A, B, C), and add() takes care of automatic C reallocation.
    • s – Scalar assigned to each matrix element. The matrix size or type is not changed.

    These are available assignment operators. Since they all are very different, make sure to read the operator parameters description.

     1 int main(int argc, char** argv)
     2 {
     3     Mat m = Mat(8, 8, CV_8UC1);
     4 
     5     for (int i = 0; i < m.rows; i++)
     6         for (int j = 0; j < m.cols; j++)
     7         {
     8             m.at<uchar>(i, j) = i;    
     9         }
    10 
    11     cout << "type:" << m.type() << endl;
    12     cout << "CV_8UC1:" << CV_8UC1 << endl;
    13     cout << "depth:" << m.depth() << endl;
    14     cout << "channel:" << m.channels() << endl;
    15     printf("m-data address:%p
    ", m.data);
    16 
    17     //printMat(m);
    18 
    19     //cout << "m:" << endl;
    20     //cout << m << endl;
    21 
    22     Mat imageR = Mat::zeros(8,8,CV_8UC1); 
    23     printf("imageR-data address:%p
    ", imageR.data);
    24     //cout << imageR << endl;
    25     //cout << endl;
    26     imageR = m;//会将imageR的数据指针指向m的数据地址
    27     printf("imageR-data address:%p
    ", imageR.data);
    28     //cout << imageR << endl;
    29 
    30     //result
    31     //m-data address:0x178d3e0
    32     //imageR-data address:0x178d450
    33     //imageR-data address:0x178d3e0
    34 
    35     return 0;
    36 }
  • 相关阅读:
    IDEA最常用快捷键汇总+快速写出Main函数
    设计模式之代理模式
    Java多线程中join、yield、sleep方法详解
    git基础命令详解
    用友网络科技Java高级开发面试题(2019)
    Java内部类超详细总结(含代码示例)
    构造器中绝对绝对不能调用可被覆盖的方法
    写给小白看的Git的安装配置与使用
    Vue学习笔记5--前端工程化
    Vue学习笔记4--vue-router路由
  • 原文地址:https://www.cnblogs.com/black-mamba/p/5947976.html
Copyright © 2011-2022 走看看