Exemple #1
0
/*
 * Arguments    : const double y[128]
 *                double iPk_data[]
 *                int iPk_size[1]
 *                double iInf_data[]
 *                int iInf_size[1]
 *                double iInflect_data[]
 *                int iInflect_size[1]
 * Return Type  : void
 */
static void getAllPeaks(const double y[128], double iPk_data[], int iPk_size[1],
  double iInf_data[], int iInf_size[1], double iInflect_data[], int
  iInflect_size[1])
{
  boolean_T x[128];
  int i;
  unsigned char ii_data[128];
  int ii;
  boolean_T exitg1;
  boolean_T guard1 = false;
  double yTemp[128];
  for (i = 0; i < 128; i++) {
    x[i] = (rtIsInf(y[i]) && (y[i] > 0.0));
  }

  i = 0;
  ii = 1;
  exitg1 = false;
  while ((!exitg1) && (ii < 129)) {
    guard1 = false;
    if (x[ii - 1]) {
      i++;
      ii_data[i - 1] = (unsigned char)ii;
      if (i >= 128) {
        exitg1 = true;
      } else {
        guard1 = true;
      }
    } else {
      guard1 = true;
    }

    if (guard1) {
      ii++;
    }
  }

  if (1 > i) {
    i = 0;
  }

  iInf_size[0] = i;
  for (ii = 0; ii < i; ii++) {
    iInf_data[ii] = ii_data[ii];
  }

  memcpy(&yTemp[0], &y[0], sizeof(double) << 7);
  for (ii = 0; ii < i; ii++) {
    ii_data[ii] = (unsigned char)iInf_data[ii];
  }

  for (ii = 0; ii < i; ii++) {
    yTemp[ii_data[ii] - 1] = rtNaN;
  }

  findLocalMaxima(yTemp, iPk_data, iPk_size, iInflect_data, iInflect_size);
}
std::vector<Circle> HoughTransform::htWithRad(const PointSet& data, int radius, float strength, int circleCount){
	for (auto it = data.pts.begin(); it != data.pts.end(); ++it){
		Point cirPoint;
		float angle = 0;
		float gap = (2 * M_PI) / (360 * strength);
		for (float i = 0; i < 360 * strength; ++i){
			cirPoint.x = it->x + (radius * std::cos(angle));
			cirPoint.y = it->y + (radius * std::sin(angle));
			angle += gap;
			if (cirPoint.x < 0 || cirPoint.y < 0 || cirPoint.x > width || cirPoint.y > height){
				continue;
			}
			pixels[(int)cirPoint.x][(int)cirPoint.y] = 1 + pixels[(int)cirPoint.x][(int)cirPoint.y];
		}
	}


	std::list<std::pair<int, Point>> maximas = findLocalMaxima(circleCount);
	std::vector<Circle> circles;
	for (auto it = maximas.begin(); it != maximas.end(); ++it){
		circles.push_back(Circle(it->second, radius));
	}
	return circles;
}