标签:mic cvs 1.0 实例代码 getchar ase sdn 目标 create
矩阵和图像的操作
(1)cvAbs。cvAbsdiff。cvAbsDiffS
它们的结构为:
void cvAbs( //取src中元素的绝对值。写到dst中 const CvArr* src, const dst ); void cvAbsDiff( //src1减去src2的差的绝对值存入dst const CvArr* src1, const CvArr* src2, const dst ); void cvAbsDiffs( //src中每一个元素减去value存入dst中 const CvArr* src, CvScalar value, const dst _;
#include <cv.h> #include <highgui.h> #include <cxcore.h> #include <iostream> using namespace std; int main( int argc, char** argv ){ CvMat *mat; mat=cvCreateMat(4,4,CV_32FC1); float value = 0.0; int i = 0, j = 0; cout<<"初始化原始数组"<<endl; for ( i = 0; i < 4; i ++ ){ for( j = 0; j < 4; j ++ ){ value -= 1.0; CV_MAT_ELEM( *mat, float, i, j) = value; } } for ( i = 0; i < 4; i ++ ){ for( j = 0; j < 4; j ++ ){ cout<<"\t"<<CV_MAT_ELEM( *mat, float, i, j); } cout<<endl; } CvMat *matDes; matDes=cvCreateMat(4,4,CV_32FC1); cout<<"目标矩阵"<<endl; for ( i = 0; i < 4; i ++ ){ for( j = 0; j < 4; j ++ ){ cvmSet( matDes, i, j,0); cout<<"\t"<<CV_MAT_ELEM( *matDes, float, i, j); } cout<<endl; } cvAbs( mat, matDes ); cout<<"数组的绝对值"<<endl; for ( i = 0; i < 4; i ++ ){ for( j = 0; j < 4; j ++ ){ cout<<"\t"<<CV_MAT_ELEM( *matDes, float, i, j); } cout<<endl; } CvMat *matDiff1 = cvCreateMat(4,4,CV_32FC1); cvAbsDiff( mat,matDes , matDiff1); cout<<"两个差的绝对值"<<endl; for ( i = 0; i < 4; i ++ ){ for( j = 0; j < 4; j ++ ){ cout<<"\t"<<CV_MAT_ELEM( *matDiff1, float, i, j); } cout<<endl; } CvScalar cs; cs.val[0] = 2.0; cs.val[1] = 1.0; cvAbsDiffS( mat, matDiff1,cs); cout<<"矩阵减去标准值的绝对值"<<endl; for ( i = 0; i < 4; i ++ ){ for( j = 0; j < 4; j ++ ){ cout<<"\t"<<CV_MAT_ELEM( *matDiff1, float, i, j); } cout<<endl; } cvReleaseMat( &mat ); cvReleaseMat( &matDes ); getchar(); return 0; }
to be continued
《学习opencv》笔记——矩阵和图像操作——cvAbs,cvAbsDiff and cvAbsDiffS
标签:mic cvs 1.0 实例代码 getchar ase sdn 目标 create
原文地址:http://www.cnblogs.com/wzjhoutai/p/6979542.html