コード例 #1
0
ファイル: LFSymptom.cpp プロジェクト: telnykha/VideoA
void TSymptom::Process()
{
	awpImage* pbg = m_background.GetImage();
	awpImage* pcr = m_current.GetImage();

	awpImage* pdf = m_diff.GetImage();
	awpImage* pbn = m_binary.GetImage();
	awpImage* pbns = m_binary_source.GetImage();


	_awpZeroImage(pbn);
	_awpZeroImage(pbns);
	_awpZeroImage(pdf);
	if (pbg == NULL || pcr == NULL || pdf == NULL || pbn == NULL)
		return;
	if (pbg->sSizeX != pcr->sSizeX || pbg->sSizeY != pcr->sSizeY)
		return;
	//вычисление разницы между полученным изображением и эталонным. 
	AbsDiff();
	if (m_NumFrames < m_NumFramesToTraining)
		return;
	//нахождение бинарного изображения 
	_awpAdaptiveThreshold(pdf, pbns);
	::awpCopyImage(pbns, &pbn);
	_awpNoiseRemove(pbns);
	//awpGaussianBlur(pbns, pbn,2);
#ifdef _DEBUG
	m_background.SaveImage("background.jpg");
	m_current.SaveImage("Current.jpg");
	m_diff.SaveImage("diff.jpg");
	m_binary.SaveImage("binary.jpg");
	m_binary_source.SaveImage("binary_source.jpg");
#endif 
	//	 сопровождение найденных объектов
	for (int i = 0; i < m_BLOBs.GetCount(); i++)
	{
		TLFBLOBObject* bo = (TLFBLOBObject*)m_BLOBs.Get(i);
		bo->TrackBLOB(NULL);
	}
	//	 вычисление интегрального изображения. 
	// todo: удаление областей на бинарном изображении, занятых объектами. 
	ApplyMask(pbn);
	// анализ полученного бинарного изображения 
	// нахождение новых объектов
	Analysis(NULL);
}
コード例 #2
0
ファイル: deflate.c プロジェクト: MegaByte/zopfli
/*
Change the population counts in a way that the consequent Huffman tree
compression, especially its rle-part will be more likely to compress this data
more efficiently. length containts the size of the histogram.
*/
void OptimizeHuffmanForRle(int length, size_t* counts) {
  int i, k, stride;
  size_t symbol, sum, limit;
  int* good_for_rle;

  /* 1) We don't want to touch the trailing zeros. We may break the
  rules of the format by adding more data in the distance codes. */
  for (; length >= 0; --length) {
    if (length == 0) {
      return;
    }
    if (counts[length - 1] != 0) {
      /* Now counts[0..length - 1] does not have trailing zeros. */
      break;
    }
  }
  /* 2) Let's mark all population counts that already can be encoded
  with an rle code.*/
  good_for_rle = (int*)malloc(length * sizeof(int));
  for (i = 0; i < length; ++i) good_for_rle[i] = 0;

  /* Let's not spoil any of the existing good rle codes.
  Mark any seq of 0's that is longer than 5 as a good_for_rle.
  Mark any seq of non-0's that is longer than 7 as a good_for_rle.*/
  symbol = counts[0];
  stride = 0;
  for (i = 0; i < length + 1; ++i) {
    if (i == length || counts[i] != symbol) {
      if ((symbol == 0 && stride >= 5) || (symbol != 0 && stride >= 7)) {
        for (k = 0; k < stride; ++k) {
          good_for_rle[i - k - 1] = 1;
        }
      }
      stride = 1;
      if (i != length) {
        symbol = counts[i];
      }
    } else {
      ++stride;
    }
  }

  /* 3) Let's replace those population counts that lead to more rle codes. */
  stride = 0;
  limit = counts[0];
  sum = 0;
  for (i = 0; i < length + 1; ++i) {
    if (i == length || good_for_rle[i]
        /* Heuristic for selecting the stride ranges to collapse. */
        || AbsDiff(counts[i], limit) >= 4) {
      if (stride >= 4 || (stride >= 3 && sum == 0)) {
        /* The stride must end, collapse what we have, if we have enough (4). */
        int count = (sum + stride / 2) / stride;
        if (count < 1) count = 1;
        if (sum == 0) {
          /* Don't make an all zeros stride to be upgraded to ones. */
          count = 0;
        }
        for (k = 0; k < stride; ++k) {
          /* We don't want to change value at counts[i],
          that is already belonging to the next stride. Thus - 1. */
          counts[i - k - 1] = count;
        }
      }
      stride = 0;
      sum = 0;
      if (i < length - 3) {
        /* All interesting strides have a count of at least 4,
        at least when non-zeros. */
        limit = (counts[i] + counts[i + 1] +
                 counts[i + 2] + counts[i + 3] + 2) / 4;
      } else if (i < length) {
        limit = counts[i];
      } else {
        limit = 0;
      }
    }
    ++stride;
    if (i != length) {
      sum += counts[i];
    }
  }

  free(good_for_rle);
}
コード例 #3
0
ファイル: imavmarker.c プロジェクト: dewagter/paparazzi
struct marker_deviation_t marker(struct image_t *input, uint8_t M)
{
  struct marker_deviation_t marker_deviation;

  marker_deviation.x = 0;
  marker_deviation.y = 0;
  marker_deviation.inlier = 0;

  uint8_t *source = (uint8_t *) input->buf;
  uint16_t x, y, i, j, k;

  if (M < 1) { M = 1; }
  source = (uint8_t *) input->buf;

  int maxx = 160;
  int maxy = 120;
  int maxv = 0;

  for (j = M; j < (input->h - M); j++) {
    for (i = M; i < (input->w - M); i++) {
      int bad, good;
      good = bad = 0;
      for (k = 1; k < M; k++) {
        // Pattern must be symmetric
        bad += AbsDiff(Img(i - k, j)   , Img(i + k, j));
        bad += AbsDiff(Img(i, j - k)   , Img(i, j + k));
        bad += AbsDiff(Img(i - k, j - k) , Img(i + k, j + k));
        bad += AbsDiff(Img(i + k, j - k) , Img(i - k, j + k));

        // Pattern: Must have perpendicular contrast
        good += AbsDiff(Img(i - k, j) + Img(i + k, j),   Img(i, j - k) + Img(i, j + k));
        good += AbsDiff(Img(i - k, j - k) + Img(i + k, j + k), Img(i + k, j - k) + Img(i - k, j + k));
      }

      for (k = 4; k < M; k += 2) {
        // Pattern must be symmetric
        bad += AbsDiff(Img(i - k, j - k / 2)   , Img(i + k, j + k / 2));
        bad += AbsDiff(Img(i + k / 2, j - k)   , Img(i - k / 2, j + k));
        bad += AbsDiff(Img(i - k / 2, j - k) , Img(i + k / 2, j + k));
        bad += AbsDiff(Img(i + k, j - k / 2) , Img(i - k, j + k / 2));

        // Pattern: Must have perpendicular contrast
        good += AbsDiff(Img(i - k, j - k / 2) + Img(i + k, j + k / 2),   Img(i + k / 2, j - k) + Img(i - k / 2, j + k));
        good += AbsDiff(Img(i - k / 2, j - k) + Img(i + k / 2, j + k), Img(i + k, j - k / 2) + Img(i - k, j + k / 2));
      }

      int v = good - bad;
      if (v < 0) {
        v = 0;
      }

      if (v > maxv) {
        maxv = v;
        maxx = i;
        maxy = j;
      }

      if (v > 0) {
        Out(i, j) = 0xff;
      }
    }
  }

  // Display the marker location and center-lines.
  for (y = 0; y < input->h; y++) {
    Out(maxx, y) = 0xff;
  }
  for (x = 0; x < input->w; x++) {
    Out(x, maxy) = 0xff;
  }

  marker_deviation.x = ((int32_t)0) - ((int32_t)(input->w) / 2);
  marker_deviation.y = -((int32_t)0) + ((int32_t)(input->h) / 2);
  marker_deviation.inlier = 0;

  //printf("The number of inliers = %i\n", counter3);
  return marker_deviation;
}