使用 OpenCV 的基于C语言的 API,我需要计算 OpenCV 数组中所有元素的总和。我使用sum
(1)方法。以下是我尝试过的。
/* rgb1 is an OpenCV array */
CvScalar cvSum( const CvArr* rgb1);
printf("%lf", CvScalar.val);
但我得到编译器错误为error: expected primary-expression before ‘.’ token
.
'val' is an array of double
s. 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]);