//运行参数:girl.jpg 
#pragma comment(lib,"highgui.lib")
#pragma comment(lib,"cxcore.lib")
#pragma comment(lib,"cv.lib")
#pragma comment(lib,"ml.lib")
#pragma comment(lib,"cvaux.lib")
#pragma comment(lib,"cvcam.lib") 

#include "cv.h"
#include "highgui.h"
#include <stdio.h>

inline void cvDoubleMatPrint( const CvMat* mat );
int main( int argc, char** argv )
{
 IplImage* pImg; //声明IplImage指针

 if( argc == 2 && (pImg = cvLoadImage( argv[1], CV_LOAD_IMAGE_UNCHANGED)) != 0 )
 {
/*
	CvMat *Ma, *Mb, *Mc;
	cvMul(Ma, Mb, Mc);      // Ma.*Mb  -> Mc
	cvDiv(Ma, Mb, Mc);      // Ma./Mb  -> Mc
	cvAddS(Ma, cvScalar(-10.0), Mc); // Ma.-10 -> Mc
*/
  int i,j;
  //CvMat* M1 = cvCreateMat(4,4,CV_32FC1);
  CvMat* M1 = cvCreateMat(4,4,CV_64FC1);
  //cvSetIdentity(M1);//初始化矩阵为单位矩阵
   for(i=0;i<4;i++)
		 for(j=0;j<4;j++)
			 cvmSet(M1,i,j,2.0);
  cvDoubleMatPrint(M1);

  CvMat* M2 = cvCreateMat(4,4,CV_64FC1);


  printf("\n=====M2赋值为2.0==============\n");

   for(i=0;i<4;i++)
		 for(j=0;j<4;j++)
			 cvmSet(M2,i,j,2.0);
	CvMat* M3 = cvCreateMat(4,4,CV_64FC1);
	//(1) 矩阵之间的运算:
	//cvAdd(M1, M2, M3);
	//cvSub(M1, M2, M3);
	//cvMatMul(M1, M2, M3);

	//(2) 矩阵之间的元素级运算:
	//cvMul(M1, M2, M3);
	//cvDiv(M1, M2, M3);
	cvAddS(M1, cvScalar(-10.0), M3);

   for( i=0;i<4;i++)
   {
		 for( j=0;j<4;j++)
			 printf("%f ",cvmGet(M3,i,j));
		 printf("\n"); 
   }
  printf("\n===End:赋值为2.0==============\n");

 
  cvReleaseMat(&M1);
  cvReleaseMat(&M2);
  cvReleaseMat(&M3);

  cvNamedWindow( "Image", 1 ); // 创建窗口
  cvShowImage( "Image", pImg ); // 显示图像
  cvWaitKey(0);     // 等待按键


  cvDestroyWindow( "Image" );  // 销毁窗口
  cvReleaseImage( &pImg );  // 释放图像

  return 0;
 }

 return -1;
}

inline void cvDoubleMatPrint( const CvMat* mat )
{
    int i, j;
    for( i = 0; i < mat->rows; i++ )
    {
        for( j = 0; j < mat->cols; j++ )
        {
            printf( "%lf ",cvmGet( mat, i, j ) );
        }
        printf( "\n" );
    }
}