zoukankan      html  css  js  c++  java
  • opencv笔记三(矩阵卷积操作)

    Matlab中filter2与opencv中filter2D的比较

    比较一:横向卷积

    Matlab中filter2:

    opencv中filter2D:

    Mat C =(Mat_<float>(3,4)<<1,2,3,4,5,6,7,8,9,10,11,12);
        float *data = NULL;
        for (int row = 0; row < C.rows; row++)
        {
            data = (float *)C.ptr<float>(row);
            cout << "[";
            for (int col = 0; col < C.cols; col++)
            {
                cout << data[col] << " ";
            }
            cout << "]"  << endl;
        }
        Mat D;
        copyMakeBorder(C, D, 2, 2, 2, 2, BORDER_REPLICATE);
        for (int row = 0; row < D.rows; row++)
        {
            data = (float *)D.ptr<float>(row);
            cout << "[";
            for (int col = 0; col < D.cols; col++)
            {
                cout << data[col] << " ";
            }
            cout << "]"  << endl;
        }
        cout << endl;
    
        D = (Mat_<float>(1,3) << 0.1, 0.2 ,0.3);
        Mat E;
        filter2D(C, E, -1, D,Point(-1,-1),0, BORDER_REPLICATE);
        for (int row = 0; row < E.rows; row++)
        {
            data = (float *)E.ptr<float>(row);
            cout << "[";
            for (int col = 0; col < E.cols; col++)
            {
                cout << data[col] << " ";
            }
            cout << "]"  << endl;
        }
        cout << endl;
    View Code

    结果

     比较二:纵向卷积

    Matlab中filter2:

     opencv中filter2D:

    Mat C =(Mat_<float>(3,4)<<1,2,3,4,5,6,7,8,9,10,11,12);
        float *data = NULL;
        for (int row = 0; row < C.rows; row++)
        {
            data = (float *)C.ptr<float>(row);
            cout << "[";
            for (int col = 0; col < C.cols; col++)
            {
                cout << data[col] << " ";
            }
            cout << "]"  << endl;
        }
        Mat D;
        copyMakeBorder(C, D, 2, 2, 2, 2, BORDER_REPLICATE);
        for (int row = 0; row < D.rows; row++)
        {
            data = (float *)D.ptr<float>(row);
            cout << "[";
            for (int col = 0; col < D.cols; col++)
            {
                cout << data[col] << " ";
            }
            cout << "]"  << endl;
        }
        cout << endl;
    
        D = (Mat_<float>(3,1) << 0.1, 0.2 ,0.3);
        Mat E;
        filter2D(C, E, -1, D,Point(-1,-1),0, BORDER_REPLICATE);
        for (int row = 0; row < E.rows; row++)
        {
            data = (float *)E.ptr<float>(row);
            cout << "[";
            for (int col = 0; col < E.cols; col++)
            {
                cout << data[col] << " ";
            }
            cout << "]"  << endl;
        }
        cout << endl;
    View Code

    结果

      结论:Matlab中filter2与opencv中filter2D可以得到完全一样的结果。

  • 相关阅读:
    Zookeeper数据类型
    Zookeeper基本命令
    Redis集群
    Mysql 模拟自增主键
    git回滚版本操作
    Redis缓存穿透和雪崩
    日期格式jackson格式化
    Zookeeper安装
    redis主从复制
    Redis哨兵模式
  • 原文地址:https://www.cnblogs.com/walker-lin/p/11578940.html
Copyright © 2011-2022 走看看