1:cvAbs原型为 void cvAbs(CvMat* src,CvMat* dst),计算src中的所有元素的绝对值,然后将值赋给dst中的元素。示例代码如下:
#include "stdafx.h"
#include "highgui.h"
#include "cv.h"
#include "iostream"
using namespace std;
#include <cxcore.h>
void PrintMat2(CvMat*target, char * name)//第一个参数为cvMat矩阵指针,第二个参数为输出的矩阵的名字
{
printf("%s:\n", name);
for (int i=0; i<target->rows; i++)
{
for (int j=0; j<target->cols;j++)
{
printf("%f\t", cvmGet(target, i,j));
}
printf("\n");
}
}
int main()
{
float vals[]={0.866,-0.500,0.500,-0.866};
CvMat rotmat;
//cvInitMatHeader(CvMat矩阵指针,行数,列数,数据类型,一维矩阵指针)
cvInitMatHeader(&rotmat,2,2,CV_32FC1,vals);
PrintMat2(&rotmat,"romat");
CvMat* dst=cvCreateMat(2,2,CV_32FC1);
cvAbs(&rotmat,dst);
PrintMat2(dst,"用cvAbs取绝对值后");
return 0;
}
运行结果: