コード例 #1
0
ファイル: image_class.cpp プロジェクト: V-Italy/optical_flow
double FlowField::CalcAngularError(FlowField &t){
  std::pair<int, int> size = Size();
  double amount = 0;
  double tmp1 = 0;
  double tmp2 = 0;
  double sum_l2 = 0;
  double sum_ang = 0;

  // make sure both flow field have same size
  if (size != t.Size()){
    std::cout << "Dimensions in CalcAngularError dont match" << std::endl;
    std::exit(1);
  }

  for (int i = 0; i < size.first; i++) {
    for (int j = 0; j < size.second; j++){
      // test if reference flow vector exists
      if (t.u[i][j] != 100.0 || t.v[i][j] != 100.0){
        amount++;
        tmp1 = t.u[i][j] - u[i][j];
        tmp2 = t.v[i][j] - v[i][j];

        sum_l2 += sqrt(tmp1*tmp1 + tmp2*tmp2);
        tmp1 = (t.u[i][j] * u[i][j] + t.v[i][j] * v[i][j] + 1.0)
   		     / sqrt( (t.u[i][j] * t.u[i][j] + t.v[i][j] * t.v[i][j] + 1.0)
   			     * (u[i][j] * u[i][j] + v[i][j] * v[i][j] + 1.0) );

        if (tmp1 > 1.0) tmp1 = 1.0;
        if (tmp1 < - 1.0) tmp1 = - 1.0;
        sum_ang += acos(tmp1) * 180.0/M_PI;
      }
    }
  }

  return sum_ang / amount;
}