矩阵和图像的操作
(1)cvDet函数
其结构
double cvDet(//计算矩阵的行列式 const CvArr* mat );
#include <cv.h> #include <highgui.h> #include <stdio.h> #include <iostream> using namespace std; int main() { double va[] = {1,0,0,0,2,0,0,0,3}; CvMat Va=cvMat(3, 3, CV_64FC1, va); cout << "该矩阵的行列式的值为"<<cvDet(&Va) << endl; getchar(); return 0; }
(2)cvDiv函数
其结构
void cvDiv(//矩阵元素相除 const CvArr* src1,//被除矩阵 const CvArr* src2,//除矩阵 CvArr* dst,//结果矩阵 double scale = 1//被除矩阵因子 );
#include <cv.h> #include <highgui.h> #include <stdio.h> #include <iostream> using namespace std; int main() { double va[] = {2,4,6,8,10,12,14,16,18}; CvMat Va=cvMat(3, 3, CV_64FC1, va); double vb[] = {1,2,3,4,5,6,7,8,9}; CvMat Vb=cvMat(3, 3, CV_64FC1, vb); cout<< "矩阵A:"<<endl; for(int i = 0 ;i < 3 ; i++) { for(int j = 0; j < 3; j++) cout << CV_MAT_ELEM(Va,double,i,j)<<" "; cout << endl; } cout<< "矩阵B:"<<endl; for(int i = 0 ;i < 3 ; i++) { for(int j = 0; j < 3; j++) cout << CV_MAT_ELEM(Vb,double,i,j)<<" "; cout << endl; } cvDiv(&Va,&Vb,&Va,); cout<< "运算后的矩阵:"<<endl; for(int i = 0 ;i < 3 ; i++) { for(int j = 0; j < 3; j++) cout << CV_MAT_ELEM(Va,double,i,j)<<" "; cout << endl; } getchar(); return 0; }
(3)cvDotProduct函数
其结构
double cvDotProduct(//计算向量点积 const CvArr* src1, const CvArr* src2 );
实例代码
#include <cv.h> #include <highgui.h> #include <stdio.h> #include <iostream> using namespace std; int main() { double va[] = {1,2,3}; double vb[] = {3,2,1}; CvMat Va=cvMat(3, 1, CV_64FC1, va); CvMat Vb=cvMat(3, 1, CV_64FC1, vb); cout << "其内积为:" << cvDotProduct(&Va,&Vb); getchar(); return 0; }
(4)cvEigenVV函数
其结构
double cvEigenVV(//对称矩阵求特征值和特征向量 CvArr* mat,//目标矩阵 CvArr* evects,//特征向量 CvArr* evals,//特征值 double eps = 0//设置偏离尺寸 );
#include <cv.h> #include <highgui.h> #include <stdio.h> #include <iostream> using namespace std; int main() { double a[3][3] = { {1,0,0}, {0,2,0}, {0,0,3} }; CvMat va=cvMat(3,3, CV_64FC1,a); double b[3][3] = { {0,0,0}, {0,0,0}, {0,0,0} }; CvMat vb =cvMat(3, 3, CV_64FC1, b); double c[3] = {0,0,0}; CvMat vc = cvMat(3,1, CV_64FC1, c); cvEigenVV(&va,&vb,&vc,1.0e-6F); cout << endl; cout << "特征向量为:" << endl; for(int i=0;i<3;i++) { cout << "第"<< i <<"个特征向量为:" << endl; for(int j=0;j<3;j++) printf("%f\t",cvmGet(&vb,i,j)); cout << endl; } cout << "特征值为:" << endl; for(int i=0;i<3;i++) { cout << "第"<< i <<"个特征值为:" << endl; printf("%f",cvmGet(&vc,i,0)); cout << endl; } getchar(); return 0; }
(5)cvFlip函数
其结构
void cvFlip(//将图像绕X轴或Y轴旋转 const CvArr* src, //目标图像 CvArr* dst = NULL,//如果为零则内部旋转,否则为结果矩阵 int flip_mode = 0//旋转样式:0绕X轴转,正值绕Y轴,负值绕X和Y轴 );
#include <cv.h> #include <highgui.h> #include <stdio.h> int main(int argc, char** argv) { IplImage *src2,*src3; src2=cvLoadImage("1.jpg"); src3=cvLoadImage("7.jpg"); cvFlip(src2,src3,-1); cvShowImage( "测试2", src2); cvShowImage( "测试3", src3); cvWaitKey(); return 0; }
to be continued
《学习opencv》笔记——矩阵和图像操作——cvDet,cvDit,cvDotProduct,cvEigenVV and cvFlip,布布扣,bubuko.com
《学习opencv》笔记——矩阵和图像操作——cvDet,cvDit,cvDotProduct,cvEigenVV and cvFlip
原文地址:http://blog.csdn.net/zhurui_idea/article/details/28452829