opencv3.0 均值 标准差 函数 mean meanStdDev


   opencv库函数 sum 求和  mean  求均值
  Scalar Cbsum2 = sum(Cb);
  Scalar Crsum2 = sum(Cr);
  Scalar Cbmean2 = mean(Cb);
  Scalar Crmean2 = mean(Cr);
  cout << "Cbsum:" << Cbsum2[0] << "  Cbmean:" << Cbmean2[0] << endl;  //"  Cbvar:" << Cbvar << endl;
  cout << "Crsum:" << Crsum2[0] << "  Crmean:" << Crmean2[0] << endl;

  // opencv库 求标准差函数 
  Mat b_m,b_sd,r_m,r_sd;
  double bm = 0, bsd = 0, rm = 0, rsd = 0;
  meanStdDev(Cb, b_m, b_sd);  // Cb 通道
  meanStdDev(Cr, r_m, r_sd);  // Cr 通道
  bm = b_m.at(0, 0);  bsd = b_sd.at(0, 0);
  rm = r_m.at(0, 0);  rsd = r_sd.at(0, 0);
  cout << "Cb--Mean: " << bm << " , StdDev: " << bsd << endl;
  cout << "Cr--Mean: " << rm << " , StdDev: " << rsd << endl;



mean, meanStdDev计算结果是double类型的。
mean返回的值是Scalar,就是vector类型的数组。所以当要Scalar的元素,要用[n]方式访问。
meanStdDev计算的均值和标准差都以Mat形式返回,这里返回的是1X1的矩阵。所以访问结果,要访问Mat的元素。



你可能感兴趣的:(opencv,c++)