@Override
 public void beforeUpdate(MBFImage frame) {
   if (transform != null) {
     MBFImage bgCopy = mbfImage.clone();
     MBFProjectionProcessor proj = new MBFProjectionProcessor();
     proj.setMatrix(transform);
     proj.accumulate(frame);
     proj.performProjection(0, 0, bgCopy);
     panel.setImage(bimg = ImageUtilities.createBufferedImageForDisplay(bgCopy, bimg));
   } else panel.setImage(bimg = ImageUtilities.createBufferedImageForDisplay(frame, bimg));
 }
Beispiel #2
0
  @Override
  public synchronized void afterUpdate(final VideoDisplay<MBFImage> display) {
    if (this.matcher != null && !this.videoFrame.isPaused()) {
      final MBFImage capImg = this.videoFrame.getVideo().getCurrentFrame();
      final LocalFeatureList<Keypoint> kpl = this.engine.findFeatures(capImg);

      final MBFImageRenderer renderer = capImg.createRenderer();
      renderer.drawPoints(kpl, RGBColour.MAGENTA, 3);

      MBFImage matches;
      if (this.matcher.findMatches(kpl)) {
        try {
          // Shape sh =
          // modelImage.getBounds().transform(((MatrixTransformProvider)
          // matcher.getModel()).getTransform().inverse());
          // renderer.drawShape(sh, 3, RGBColour.BLUE);
          final Matrix boundsToPoly =
              ((MatrixTransformProvider) this.matcher.getModel()).getTransform().inverse();
          this.renderMode.render(renderer, boundsToPoly, this.modelImage.getBounds());
        } catch (final RuntimeException e) {
        }

        matches =
            MatchingUtilities.drawMatches(
                this.modelImage, capImg, this.matcher.getMatches(), RGBColour.RED);
      } else {
        matches =
            MatchingUtilities.drawMatches(
                this.modelImage, capImg, this.matcher.getMatches(), RGBColour.RED);
      }

      this.matchPanel.setPreferredSize(this.matchPanel.getSize());
      this.matchFrame.setImage(ImageUtilities.createBufferedImageForDisplay(matches));
    }
  }
Beispiel #3
0
  @Override
  public synchronized void keyPressed(final KeyEvent key) {
    if (key.getKeyCode() == KeyEvent.VK_SPACE) {
      this.videoFrame.togglePause();
    } else if (key.getKeyChar() == 'c'
        && this.polygonListener.getPolygon().getVertices().size() > 2) {
      try {
        final Polygon p = this.polygonListener.getPolygon().clone();
        this.polygonListener.reset();
        this.modelImage =
            this.capture
                .getCurrentFrame()
                .process(new PolygonExtractionProcessor<Float[], MBFImage>(p, RGBColour.BLACK));

        if (this.matcher == null) {
          // configure the matcher
          final HomographyModel model = new HomographyModel();
          final RANSAC<Point2d, Point2d, HomographyModel> ransac =
              new RANSAC<Point2d, Point2d, HomographyModel>(
                  model,
                  new SingleImageTransferResidual2d<HomographyModel>(),
                  3.0,
                  1500,
                  new RANSAC.ProbabilisticMinInliersStoppingCondition(0.01),
                  true);
          this.matcher =
              new ConsistentLocalFeatureMatcher2d<Keypoint>(
                  new FastBasicKeypointMatcher<Keypoint>(8));
          this.matcher.setFittingModel(ransac);

          this.modelPanel.setPreferredSize(this.modelPanel.getSize());
        }

        this.modelFrame.setImage(ImageUtilities.createBufferedImageForDisplay(this.modelImage));

        final DoGColourSIFTEngine engine = new DoGColourSIFTEngine();
        engine.getOptions().setDoubleInitialImage(true);

        this.matcher.setModelFeatures(engine.findFeatures(this.modelImage));
      } catch (final Exception e) {
        e.printStackTrace();
      }
    } else if (key.getKeyChar() == '1') {
      this.renderMode = RenderMode.SQUARE;
    } else if (key.getKeyChar() == '2') {
      this.renderMode = RenderMode.PICTURE;
    } else if (key.getKeyChar() == '3') {
      this.renderMode = RenderMode.VIDEO;
    }
  }