• Win7系统Visual Studio下的armadillo环境配置


    Armadillo 环境配置

    Armadillo是一款对于C++的线性代数库,可以进行矩阵运算,在MATLAB转C/C++时可以更加方便。下面是armadillo的安装和配置。

    这里写图片描述

    首先,下载armadillo,地址(http://arma.sourceforge.net/)。

    这里选择稳定版本armadillo-8.100.1,解压,将其中的include文件夹复制到指定的文件夹下。(这里将其拷贝至D:/Armadillo)

    修改D:Armadilloincludearmadillo_bits中的config.hpp

    这里写图片描述

    取消以下两句中的注释符号,如上图所示。

    #define ARMA_USE_LAPACK
    #define ARMA_USE_BLAS

    这样表示使用LAPACK和BLAS两个库。1

    BLAS的官方文档介绍:

    The BLAS (Basic Linear Algebra Subprograms)are routines that provide standard building blocks for performing basic vectorand matrix operations. The Level 1 BLAS perform scalar, vector andvector-vector operations, the Level 2 BLAS perform matrix-vector operations,and the Level 3 BLAS perform matrix-matrix operations. Because the BLAS areefficient, portable, and widely available, they are commonly used in thedevelopment of high quality linear algebra software, LAPACK for example.

    LAPACK的官方文档介绍:

    LAPACK is written in Fortran 90 and providesroutines for solving systems of simultaneous linear equations, least-squaressolutions of linear systems of equations, eigenvalue problems, and singularvalue problems. The associated matrix factorizations (LU, Cholesky, QR, SVD,Schur, generalized Schur) are also provided, as are related computations suchas reordering of the Schur factorizations and estimating condition numbers.Dense and banded matrices are handled, but not general sparse matrices. In allareas, similar functionality is provided for real and complex matrices, in bothsingle and double precision.

    需要下载LAPACK和BLAS两个库,实际上armadillo自带这两个库,在.armadillo-8.100.1exampleslib_win64中,但是是64位,因此需要下载32位的这两个库。

    下载完成后,在visual studio中配好lib目录,include目录,附加依赖项。(配置方法类似上文opencv库的配法)。运行程序,出错。报错如下:

    这里写图片描述

    提示没有lapack32位的动态链接库dll文件。下载lapack_win32_MTd.dll和blas_win32_MTd.dll以及不带d的版本(release版)的dll,拷贝至指定目录,此处是Windows中的SysWOW64。再运行程序,点击生成解决方案,查看结果。

    例程:

    #include<opencv2/opencv.hpp>
    #include <armadillo>
    #include <iostream>
    using namespace cv;
    using namespace arma;
    using namespace std;
    int main()
    {
        arma::matA = arma::randu<mat>(5,5);
        cout<<"A= "<<A<<endl;
        cout<<"det(A)= "<<arma::det(A)<<endl;
        cv::Matimg = cv::imread("test.jpg",1);
        cv::Matgrey;
        cv::cvtColor(img,grey, CV_BGR2GRAY);
        cv::Matsobelx; 
        cv::Sobel(grey,sobelx, CV_32F, 1, 0);
        double minVal, maxVal; 
        cv::minMaxLoc(sobelx,&minVal, &maxVal); //find minimum and maximum intensities 
        cv::Matdraw; 
        sobelx.convertTo(draw,CV_8U, 255.0/(maxVal - minVal), -minVal * 255.0/(maxVal - minVal)); 
        cv::namedWindow("src",CV_WINDOW_AUTOSIZE); 
        cv::imshow("src",img); 
        cv::namedWindow("dst",CV_WINDOW_AUTOSIZE); 
        cv::imshow("dst",draw);
        cv::waitKey(); 
        return 0;  
    }  

    该例程即再上文中测试opencv的基础上,include进armadillo,并且using namespace arma;注意,由于armadillo和opencv中都有Mat类型,因此同时usingnamespace cv 和arma会出现冲突,因此需要域运算符。

    结果如下(只显示console中的结果):

    这里写图片描述

    成功啦~哈哈哈

    附录:MATLAB和armadillo的转换关系

    这里写图片描述
    这里写图片描述

    Reference:

    http://arma.sourceforge.net/docs.html
    http://www.netlib.org/blas/
    http://www.netlib.org/lapack/
    

    这里写图片描述


    1. 【注:LAPACK是LinearAlgebra PACKage的缩写,由其官方文档(如下)可以看出,LAPACK可以解决线性方程,最小二乘法,特征值分解,以及各类矩阵分解,如LU,QR,Cholesky,svd等。而BLAS是Basic Linear Algebra Subprograms的缩写,可以看出,BLAS提供较为底层的矢量和矩阵运算,Level1标量,矢量,矢量-矢量,Level2 矢量-矩阵,Level3 矩阵-矩阵,LAPACK也是基于BLAS】
  • 相关阅读:
    版本控制,django缓存,跨域问题解决
    Linux之文件系统结构
    Linux之定时任务
    Linux之LVM
    Linux之硬盘与分区
    Linux之文件重定向与查找
    Linux之文件压缩
    Linux之文件权限
    Linux之用户管理
    Linux之文件管理
  • 原文地址:https://www.cnblogs.com/morikokyuro/p/13256872.html
Copyright © 2020-2023  润新知