예제 #1
0
  @Test
  public void performLearning() {
    float interp_factor = 0.075f;

    ImageFloat32 a = new ImageFloat32(20, 25);
    ImageFloat32 b = new ImageFloat32(20, 25);

    ImageMiscOps.fill(a, 100);
    ImageMiscOps.fill(b, 200);

    CirculantTracker<ImageFloat32> alg =
        new CirculantTracker<ImageFloat32>(1f / 16, 0.2, 1e-2, 0.075, 1.0, 64, 255, interp);
    alg.initialize(a, 0, 0, 20, 25);

    // copy its internal value
    ImageFloat64 templateC = new ImageFloat64(alg.template.width, alg.template.height);
    templateC.setTo(alg.template);

    // give it two images
    alg.performLearning(b);

    // make sure the images aren't full of zero
    assertTrue(Math.abs(ImageStatistics.sum(templateC)) > 0.1);
    assertTrue(Math.abs(ImageStatistics.sum(alg.template)) > 0.1);

    int numNotSame = 0;
    // the result should be an average of the two
    for (int i = 0; i < a.data.length; i++) {
      if (Math.abs(a.data[i] - alg.templateNew.data[i]) > 1e-4) numNotSame++;

      // should be more like the original one than the new one
      double expected =
          templateC.data[i] * (1 - interp_factor) + interp_factor * alg.templateNew.data[i];
      double found = alg.template.data[i];

      assertEquals(expected, found, 1e-4);
    }

    // make sure it is actually different
    assertTrue(numNotSame > 100);
  }
  protected void performThresholding(float threshLow, float threshHigh, ImageUInt8 output) {
    if (hysteresisPts != null) {
      hysteresisPts.process(suppressed, direction, threshLow, threshHigh);

      // if there is an output image write the contour to it
      if (output != null) {
        ImageMiscOps.fill(output, 0);
        for (EdgeContour e : hysteresisPts.getContours()) {
          for (EdgeSegment s : e.segments)
            for (Point2D_I32 p : s.points) output.unsafe_set(p.x, p.y, 1);
        }
      }
    } else {
      hysteresisMark.process(suppressed, direction, threshLow, threshHigh, output);
    }
  }
  @Override
  public void renderTarget(ImageFloat32 original, List<CalibrationObservation> solutions) {
    ImageMiscOps.fill(original, 255);

    int numRows = config.numRows * 2 - 1;
    int numCols = config.numCols * 2 - 1;

    int square = original.getWidth() / (Math.max(numRows, numCols) + 4);

    int targetWidth = square * numCols;
    int targetHeight = square * numRows;

    int x0 = (original.width - targetWidth) / 2;
    int y0 = (original.height - targetHeight) / 2;

    for (int i = 0; i < numRows; i += 2) {
      int y = y0 + i * square;

      for (int j = 0; j < numCols; j += 2) {
        int x = x0 + j * square;
        ImageMiscOps.fillRectangle(original, 0, x, y, square, square);
      }
    }

    int pointsRow = numRows + 1;
    int pointsCol = numCols + 1;

    CalibrationObservation set = new CalibrationObservation();
    int gridIndex = 0;
    for (int i = 0; i < pointsRow; i++) {
      for (int j = 0; j < pointsCol; j++, gridIndex++) {
        double y = y0 + i * square;
        double x = x0 + j * square;
        set.add(new Point2D_F64(x, y), gridIndex);
      }
    }
    solutions.add(set);
  }
  @Test
  public void checkRender() {
    // Easier to make up a plane in this direction
    Se3_F64 cameraToPlane = new Se3_F64();
    ConvertRotation3D_F64.eulerToMatrix(
        EulerType.XYZ, UtilAngle.degreeToRadian(0), 0, 0, cameraToPlane.getR());
    cameraToPlane.getT().set(0, -5, 0);

    Se3_F64 planeToCamera = cameraToPlane.invert(null);

    CreateSyntheticOverheadViewMS<ImageFloat32> alg =
        new CreateSyntheticOverheadViewMS<ImageFloat32>(
            TypeInterpolate.BILINEAR, 3, ImageFloat32.class);

    alg.configure(param, planeToCamera, centerX, centerY, cellSize, overheadW, overheadH);

    MultiSpectral<ImageFloat32> input =
        new MultiSpectral<ImageFloat32>(ImageFloat32.class, width, height, 3);
    for (int i = 0; i < 3; i++) ImageMiscOps.fill(input.getBand(i), 10 + i);

    MultiSpectral<ImageFloat32> output =
        new MultiSpectral<ImageFloat32>(ImageFloat32.class, overheadW, overheadH, 3);

    alg.process(input, output);

    for (int i = 0; i < 3; i++) {
      ImageFloat32 o = output.getBand(i);

      // check parts that shouldn't be in view
      assertEquals(0, o.get(0, 300), 1e-8);
      assertEquals(0, o.get(5, 0), 1e-8);
      assertEquals(0, o.get(5, 599), 1e-8);

      // check areas that should be in view
      assertEquals(10 + i, o.get(499, 300), 1e-8);
    }
  }