opencv C++ CvMat 程序结果不对
这是我的程序和结果,我检查了好几遍看不出错误在哪,结果应该是8.7才对呀?希望大侠指教~~~#include"stdafx.h"#include"iostream"#in...
这是我的程序和结果,我检查了好几遍看不出错误在哪,结果应该是8.7才对呀?希望大侠指教~~~
#include "stdafx.h"
#include "iostream"
#include <cv.h>
float sum( CvMat* mat )
{
float s = 0;
for( int row=0; row<mat->rows; row++ )
{
const float* ptr = (const float*)(mat->data.ptr + row * mat->step);
for( int col=0; col<mat->cols; col++ )
{
s += *ptr++;
}
}
return( s );
};
int main(int argc, char** argv)
{
CvMat *mat = cvCreateMat(5,5,CV_32FC1);
float element_3_2 = 7.7;
*((float*)CV_MAT_ELEM_PTR( *mat, 3,2) ) = element_3_2;
cvmSet(mat,4,4,0.5000);
cvSetReal2D(mat,3,3,0.5000);
float s = sum(mat);
printf("%f\n",s);
system("pause");
return 0;
} 展开
#include "stdafx.h"
#include "iostream"
#include <cv.h>
float sum( CvMat* mat )
{
float s = 0;
for( int row=0; row<mat->rows; row++ )
{
const float* ptr = (const float*)(mat->data.ptr + row * mat->step);
for( int col=0; col<mat->cols; col++ )
{
s += *ptr++;
}
}
return( s );
};
int main(int argc, char** argv)
{
CvMat *mat = cvCreateMat(5,5,CV_32FC1);
float element_3_2 = 7.7;
*((float*)CV_MAT_ELEM_PTR( *mat, 3,2) ) = element_3_2;
cvmSet(mat,4,4,0.5000);
cvSetReal2D(mat,3,3,0.5000);
float s = sum(mat);
printf("%f\n",s);
system("pause");
return 0;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询