-1

使用 OpenCV 的基于C语言的 API,我需要计算 OpenCV 数组中所有元素的总和。我使用sum1)方法。以下是我尝试过的。

/* rgb1 is an OpenCV array */
CvScalar cvSum( const CvArr* rgb1);
printf("%lf", CvScalar.val);

但我得到编译器错误为error: expected primary-expression before ‘.’ token.

4

1 回答 1

2

'val' is an array of doubles. You need to access it via val[0], and printf it using %f

You also have a bug. What you wrote in not valid C code.
It should be this:

CvScalar sum = cvSum(rgb1);
printf("%f", sum.val[0]);

or if you don't want the variable:

printf("%f", cvSum(rgb1).val[0]);
于 2013-07-15T12:18:15.270 回答