c++ opencv 数学函数示例

// ConsoleApplication11.cpp : Defines the entry point for the console application.
//


#include "stdafx.h"
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
CvMat *mat = cvCreateMat(3, 4, CV_32FC1);
cvRange(mat, 0.0, 100.0);
CvRNG rng;
cvRandShuffle(mat, &rng, 1.0);
for (int i = 0; i < mat->rows; i++){
for (int j = 0; j < mat->cols; j++){
printf("%f ", cvmGet(mat, i, j));
}
printf("\n");
}
printf("\n");


CvMat *mat1 = cvCloneMat(mat);
CvMat *mat2 = cvCloneMat(mat);
cvSub(mat, mat1, mat2);
for (int i = 0; i < mat->rows; i++){
for (int j = 0; j < mat->cols; j++){
printf("%f ", cvmGet(mat2, i, j));
}
printf("\n");
}
printf("\n");


Scalar sca = cvSum(mat);
Scalar sca1 = cvAvg(mat);


cvPow(mat, mat2, 3.3);
for (int i = 0; i < mat->rows; i++){
for (int j = 0; j < mat->cols; j++){
printf("%f ", cvmGet(mat2, i, j));
}
printf("\n");
}
printf("\n");


cvLog(mat, mat2);
for (int i = 0; i < mat->rows; i++){
for (int j = 0; j < mat->cols; j++){
printf("%f ", cvmGet(mat2, i, j));
}
printf("\n");
}
printf("\n");


cvExp(mat, mat2);
for (int i = 0; i < mat->rows; i++){
for (int j = 0; j < mat->cols; j++){
printf("%f ", cvmGet(mat2, i, j));
}
printf("\n");
}
printf("\n");


cvAbsDiff(mat, mat1, mat2);
for (int i = 0; i < mat->rows; i++){
for (int j = 0; j < mat->cols; j++){
printf("%f ", cvmGet(mat2, i, j));
}
printf("\n");
}
printf("\n");


cvAbsDiffS(mat, mat2, Scalar(255, 0, 0));
for (int i = 0; i < mat->rows; i++){
for (int j = 0; j < mat->cols; j++){
printf("%f ", cvmGet(mat2, i, j));
}
printf("\n");
}
printf("\n");


cvMax(mat, mat1, mat2);
for (int i = 0; i < mat->rows; i++){
for (int j = 0; j < mat->cols; j++){
printf("%f ", cvmGet(mat2, i, j));
}
printf("\n");
}
printf("\n");


cvMaxS(mat, 50.0, mat2);
for (int i = 0; i < mat->rows; i++){
for (int j = 0; j < mat->cols; j++){
printf("%f ", cvmGet(mat2, i, j));
}
printf("\n");
}
printf("\n");


cvMin(mat, mat1, mat2);
for (int i = 0; i < mat->rows; i++){
for (int j = 0; j < mat->cols; j++){
printf("%f ", cvmGet(mat2, i, j));
}
printf("\n");
}
printf("\n");


cvMinS(mat, 1.5, mat2);
for (int i = 0; i < mat->rows; i++){
for (int j = 0; j < mat->cols; j++){
printf("%f ", cvmGet(mat2, i, j));
}
printf("\n");
}
printf("\n");




IplImage *pl = cvCreateImage(cvSize(50, 50), IPL_DEPTH_64F, 3);
IplImage *pl1 = cvCreateImage(cvSize(50, 50), IPL_DEPTH_64F, 1);
IplImage *pl2 = cvCreateImage(cvSize(50, 50), IPL_DEPTH_64F, 1);
IplImage *pl3 = cvCreateImage(cvSize(50, 50), IPL_DEPTH_64F, 1);
cvSplit(pl, pl1, pl2, pl3, NULL);


return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

 

posted @ 2015-08-05 19:42  QQ76211822  阅读(255)  评论(0编辑  收藏  举报