6 其他运算
6.1 指数和对数运算
- 针对矩阵中每一个数值进行相应的运算
- exp函数
- log函数:以e为底
- 以上两个函数的输入矩阵的数据类型只能是CV_32F或者CV_64F
#include <opencv2/core/core.hpp>
#include<iostream>
using namespace std;
using namespace cv;
int main(){
Mat src1 = (Mat_<double>(2, 3) << 1,2,3,4,5,6);
Mat dst;
cout << src1 << endl;
log(src1,dst);
cout << dst << endl;
return 0;
}
#include <opencv2/core/core.hpp>
#include<iostream>
using namespace std;
using namespace cv;
int main(){
Mat src1 = (Mat_<double>(2, 3) << 1,2,3,4,5,6);
Mat dst;
cout << src1 << endl;
exp(src1,dst);
cout << dst << endl;
return 0;
}
6.2 幂指数和开平方运算
- pow函数:数据类型不受限制
- sqrt函数:输入矩阵的数据类型只能是CV_32F或者CV_64F
#include <opencv2/core/core.hpp>
#include<iostream>
using namespace std;
using namespace cv;
int main(){
Mat src1 = (Mat_<double>(2, 3) << 1,2,3,4,5,6);
Mat dst;
cout << src1 << endl;
pow(src1,2,dst);
cout << dst << endl;
return 0;
}
#include <opencv2/core/core.hpp>
#include<iostream>
using namespace std;
using namespace cv;
int main(){
Mat src1 = (Mat_<double>(2, 3) << 1,4,9,16,25,36);
Mat dst;
cout << src1 << endl;
sqrt(src1,dst);
cout << dst << endl;
return 0;
}