/* #define cvAbs( src, dst ) cvAbsDiffS( (src), (dst), cvScalarAll(0)) cvAbsDiffS( const CvArr* srcarr1, CvArr* dstarr, CvScalar scalar ) {     cv::Mat src1 = cv::cvarrToMat(srcarr1), dst = cv::cvarrToMat(dstarr);     CV_Assert( src1.size() == dst.size() && src1.type() == dst.type() );      cv::absdiff( src1, scalar, dst ); }  CV_EXPORTS void absdiff(const Mat& a, const Mat& b, Mat& c); CV_EXPORTS void absdiff(const Mat& a, const Scalar& s, Mat& c);   /****************************************************************************************\ *                                      absdiff                                           * \****************************************************************************************/ /* template<typename T> struct OpAbsDiff {     typedef T type1;     typedef T type2;     typedef T rtype;     T operator()(T a, T b) { return (T)std::abs(a - b); } };  template<> inline short OpAbsDiff<short>::operator ()(short a, short b) { return saturate_cast<short>(std::abs(a - b)); }  template<typename T, typename WT=T> struct OpAbsDiffS {     typedef T type1;     typedef WT type2;     typedef T rtype;     T operator()(T a, WT b) { return saturate_cast<T>(std::abs(a - b)); } };  void absdiff( const Mat& src1, const Mat& src2, Mat& dst ) {     static BinaryFunc tab[] =     {         binaryOpC1_<OpAbsDiff<uchar>,VAbsDiff8u>, 0,         binaryOpC1_<OpAbsDiff<ushort>,VAbsDiff16u>,         binaryOpC1_<OpAbsDiff<short>,VAbsDiff16s>,         binaryOpC1_<OpAbsDiff<int>,NoVec>,         binaryOpC1_<OpAbsDiff<float>,VAbsDiff32f>,         binaryOpC1_<OpAbsDiff<double>,NoVec>, 0     };      dst.create(src1.size(), src1.type());     BinaryFunc func = tab[src1.depth()];     CV_Assert(src1.size() == src2.size() && src1.type() == src2.type() && func != 0);     func( src1, src2, dst ); }   void absdiff( const Mat& src1, const Scalar& s, Mat& dst ) {     static BinarySFuncCn tab[] =     {         binarySOpCn_<OpAbsDiffS<uchar, int> >, 0,         binarySOpCn_<OpAbsDiffS<ushort, int> >,         binarySOpCn_<OpAbsDiffS<short, int> >,         binarySOpCn_<OpAbsDiffS<int> >,         binarySOpCn_<OpAbsDiffS<float> >,         binarySOpCn_<OpAbsDiffS<double> >, 0     };      dst.create(src1.size(), src1.type());     BinarySFuncCn func = tab[src1.depth()];     CV_Assert(src1.channels() <= 4 && func != 0);     func( src1, dst, s ); } */


#include "stdafx.h" #include <cv.h> #include <highgui.h> #include <cxcore.h> #include <iostream> using namespace std; int main( int argc, char** argv ) {   	CvMat *mat; 	mat=cvCreateMat(3,4,CV_32FC1); 	 	float value = 0.0; 	int i = 0, j = 0; 	cout<<"初始化原始数组"<<endl; 	for ( i = 0; i < 3; i ++ ){ 		for( j = 0; j < 4; j ++ ){ 			 			value -= 3.0; 			CV_MAT_ELEM( *mat, float, i, j) = value;		 		} 	} 	cout<<"赋值后"<<endl; 	for ( i = 0; i < 3; i ++ ){ 		for( j = 0; j < 4; j ++ ){ 			 			cout<<" "<<CV_MAT_ELEM( *mat, float, i, j);	 		} 		cout<<endl; 	}  	CvMat *matDes; 	matDes=cvCreateMat(3,4,CV_32FC1); 	cout<<"目标矩阵"<<endl; 	for ( i = 0; i < 3; i ++ ){ 		for( j = 0; j < 4; j ++ ){ 			 			cout<<" "<<CV_MAT_ELEM( *matDes, float, i, j);		 		} 		 		cout<<endl; 	} 	// 	 cvAbsDiffS(mat,matDes,cvScalarAll(0));     	 cvAbs( mat, matDes ); 	cout<<"数组的绝对值"<<endl; 	for ( i = 0; i < 3; i ++ ){ 		for( j = 0; j < 4; j ++ ){ 			 			cout<<" "<<CV_MAT_ELEM( *matDes, float, i, j);		 		} 		 		cout<<endl; 	} 	cvReleaseMat( &mat ); 	cvReleaseMat( &matDes ); 	system("pause"); 	return 0; }