本文共 2950 字,大约阅读时间需要 9 分钟。
矩阵和图像的操作
(1)cvSetIdentity函数
其结构
void cvSetIdentity(//将矩阵行与列相等的元素置为1。其余元素置为0 CvArr* arr//目标矩阵);
#include#include #include #include using namespace std;int main() { double a[3][3] = { {1,2,3}, {4,5,6}, {7,8,9} }; CvMat va = cvMat(3,3, CV_64FC1,a); cout<<"目标矩阵:"<
(2)cvSolve函数
其结构
int cvSolve(//求解线性方程组解 src*dst = src2 const CvArr* src1,//系数矩阵 const CvArr* src2,//常数矩阵 CvArr* dst,//解矩阵 int method = CV_LU//用法);
#include#include #include #include using namespace std;int main() { cout<< "计算A*X = B中的解X:" <
(3)cvSplit函数
其结构
void cvSplit(//分解多通道图像为各个单通道 const CvArr* src,//目标图像 CvArr* dst0,//单通道图像1 CvArr* dst1,//单通道图像2 CvArr* dst2,//单通道图像3 CvArr* dst3//单通道图像4);
#include#include #include int main() { IplImage *src1,*dst1,*dst2,*dst3,*dst4; src1=cvLoadImage("3.jpg",1); dst1 = cvCreateImage(cvSize(src1->width, src1->height), IPL_DEPTH_8U, 1); dst2 = cvCreateImage(cvSize(src1->width, src1->height), IPL_DEPTH_8U, 1); dst3 = cvCreateImage(cvSize(src1->width, src1->height), IPL_DEPTH_8U, 1); cvSplit(src1, dst1, dst2, dst3, 0); cvShowImage("1",src1); cvShowImage("2",dst1); cvShowImage("3",dst2); cvShowImage("4",dst3); cvWaitKey(); return 0;}
(4)cvSub函数
其结构
void cvSub(//两个矩阵做减法 const CvArr* src1,//被减矩阵 const CvArr* src2,//减矩阵 CvArr* dst,//结果矩阵 const CvArr* mask = NULL//矩阵开关);
实例代码
#include#include #include int main() { IplImage *src1,*src2,*src3; src1 = cvLoadImage("3.jpg"); src2 = cvLoadImage("1.jpg"); src3 = cvLoadImage("7.jpg"); cvSub(src1,src2,src3); cvShowImage("1",src1); cvShowImage("2",src2); cvShowImage("3",src3); cvWaitKey(); return 0;}
(5)cvSubS函数
其结构
void cvSubS(//矩阵和值做减法 const CvArr* src,//被减矩阵 CvScalar value,//减数值 CvArr* dst,//结果矩阵 const CvArr* mask = NULL//矩阵“开关”);
#include输出结果#include #include int main() { IplImage *src1, *src2; src1 = cvLoadImage("1.jpg"); src2 = cvLoadImage("7.jpg"); CvScalar cs; cs.val[0] = 0; cs.val[1] = 255; cs.val[2] = 0; cs.val[3] = 0; cvSubS(src1,cs,src2); cvShowImage( "測试1", src1); cvShowImage( "測试2", src2); cvWaitKey(); return 0;}
(6)cvSubRS函数
其结构
void cvSubRS(//给定值减去矩阵 const CvArr* src,//减矩阵 CvScalar value,//被减数值 CvArr* dst,//结果矩阵 const CvArr* mask = NULL//矩阵“开关”);
#include#include #include int main() { IplImage *src1, *src2; src1 = cvLoadImage("1.jpg"); src2 = cvLoadImage("7.jpg"); CvScalar cs; cs.val[0] = 0; cs.val[1] = 255; cs.val[2] = 0; cs.val[3] = 0; cvSubRS(src1,cs,src2); cvShowImage( "測试1", src1); cvShowImage( "測试2", src2); cvWaitKey(); return 0;}
to be continued