private void evaluateScenario(File inputDirectory) {

    List<T> frames = new ArrayList<T>();

    IntrinsicParameters intrinsic =
        FiducialCommon.parseIntrinsic(new File(inputDirectory, "intrinsic.txt"));

    FiducialDetector<T> detector = factory.createDetector(inputDirectory);
    detector.setIntrinsic(intrinsic);

    File[] files = inputDirectory.listFiles();
    for (File f : files) {
      BufferedImage image = UtilImageIO.loadImage(f.getPath());
      if (image == null) continue;

      T frame = ConvertBufferedImage.convertFrom(image, true, detector.getInputType());
      frames.add(frame);
    }

    long startTime = System.currentTimeMillis();
    for (int trial = 0; trial < numFrames; trial++) {
      detector.detect(frames.get(trial % frames.size()));
    }
    long endTime = System.currentTimeMillis();

    double fps = numFrames / ((endTime - startTime) / 1000.0);

    outputResults.printf("%s %d %7.3f\n", inputDirectory.getPath(), numFrames, fps);
  }
예제 #2
0
  public void process(BufferedImage input) {
    setInputImage(input);

    image.reshape(input.getWidth(), input.getHeight());
    transform.reshape(input.getWidth(), input.getHeight());
    magnitude.reshape(input.getWidth(), input.getHeight());
    phase.reshape(input.getWidth(), input.getHeight());

    ConvertBufferedImage.convertFrom(input, image, true);
    fft.forward(image, transform);

    GDiscreteFourierTransformOps.shiftZeroFrequency(transform, true);

    GDiscreteFourierTransformOps.magnitude(transform, magnitude);
    GDiscreteFourierTransformOps.phase(transform, phase);

    // Convert it to a log scale for visibility
    GPixelMath.log(magnitude, magnitude);

    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            setPreferredSize(new Dimension(image.width + 50, image.height + 20));
            processedImage = true;
          }
        });

    doRefreshAll();
  }
  public RigidBodyTransform detect(BufferedImage image) {
    if (intrinsicParameters == null)
      setDefaultIntrinsicParameter(image.getHeight(), image.getWidth(), Math.PI / 4);
    ImageFloat32 gray = new ImageFloat32(image.getWidth(), image.getHeight());
    ConvertBufferedImage.convertFrom(image, gray);
    detector.setIntrinsic(intrinsicParameters);
    detector.detect(gray);

    // display the results
    if (detector.totalFound() == 0) {
      return null;
    } else {
      int closestIndex = -1;
      double closestDistance = Double.MAX_VALUE;
      Se3_F64 targetToSensor = new Se3_F64();
      for (int i = 0; i < detector.totalFound(); i++) {
        detector.getFiducialToCamera(i, targetToSensor);
        double dist = targetToSensor.getT().norm();
        if (dist < closestDistance) {
          closestIndex = i;
          closestDistance = dist;
        }
      }
      detector.getFiducialToCamera(closestIndex, targetToSensor);
      Vector3D_F64 translation = targetToSensor.getT();
      Matrix3d rotation = new Matrix3d(targetToSensor.getR().data);

      RigidBodyTransform transform =
          new RigidBodyTransform(
              rotation, new Vector3d(translation.x, translation.y, translation.z));
      return transform;
    }
  }
  public boolean estimateCameraPose(BufferedImage leftEye) {

    if (!hasIntrinsic) return false;

    gray.reshape(leftEye.getWidth(), leftEye.getHeight());
    ConvertBufferedImage.convertFrom(leftEye, gray);

    if (!target.process(gray)) return false;

    if (!computeH.computeHomography(target.getDetectedPoints())) return false;

    DenseMatrix64F H = computeH.getHomography();

    targetToOrigin.set(decomposeH.decompose(H));

    return true;
  }
  public synchronized void process(final BufferedImage input) {
    this.input = input;
    workImage = new BufferedImage(input.getWidth(), input.getHeight(), BufferedImage.TYPE_INT_RGB);

    gray.reshape(input.getWidth(), input.getHeight());
    ConvertBufferedImage.convertFrom(input, gray, true);

    detectTarget();

    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            gui.setPreferredSize(new Dimension(input.getWidth(), input.getHeight()));
            renderOutput();
          }
        });
  }
  public void evaluate(String dataName, TldTracker<T, ?> tracker) {
    System.out.println("Processing " + dataName);

    String path = "data/track_rect/TLD/" + dataName;

    Rectangle2D_F64 initial = UtilTldData.parseRectangle(path + "/init.txt");
    Rectangle2D_F64 found = new Rectangle2D_F64();

    TldVisualizationPanel gui = null;

    String imageType = new File(path + "/00001.jpg").exists() ? "jpg" : "png";

    int imageNum = 0;
    while (true) {
      String imageName = String.format("%s/%05d.%s", path, imageNum + 1, imageType);
      BufferedImage image = UtilImageIO.loadImage(imageName);
      if (image == null) break;

      input.reshape(image.getWidth(), image.getHeight());
      ConvertBufferedImage.convertFrom(image, input, true);

      boolean detected;

      if (imageNum == 0) {
        gui = new TldVisualizationPanel(this);
        gui.setFrame(image);
        gui.setSelectRectangle(false);
        ShowImages.showWindow(gui, dataName);
        tracker.initialize(
            input, (int) initial.p0.x, (int) initial.p0.y, (int) initial.p1.x, (int) initial.p1.y);
        detected = true;
      } else {
        detected = tracker.track(input);
        found.set(tracker.getTargetRegion());
      }

      if (!detected) {
        System.out.println("No Detection");
      } else {
        System.out.printf(
            "Detection: %f,%f,%f,%f\n", found.p0.x, found.p0.y, found.p1.x, found.p1.y);

        Graphics2D g2 = image.createGraphics();

        int w = (int) found.getWidth();
        int h = (int) found.getHeight();

        g2.drawRect((int) found.p0.x, (int) found.p0.y, w, h);
      }

      gui.setFrame(image);
      gui.update(tracker, detected);
      gui.repaint();

      imageNum++;

      while (paused) {
        Thread.yield();
      }

      //			BoofMiscOps.pause(30);
    }
    System.out.println();
  }
예제 #7
0
  public static void main(String[] args) {

    String nameIntrinsic = null;
    int cameraId = 0;

    if (args.length >= 1) {
      cameraId = Integer.parseInt(args[0]);
    }
    if (args.length >= 2) {
      nameIntrinsic = args[1];
    } else {
      System.out.println();
      System.out.println("SERIOUSLY YOU NEED TO CALIBRATE THE CAMERA YOURSELF!");
      System.out.println("There will be a lot more jitter and inaccurate pose");
      System.out.println();
    }

    System.out.println();
    System.out.println("camera ID = " + cameraId);
    System.out.println("intrinsic file = " + nameIntrinsic);
    System.out.println();

    Webcam webcam = Webcam.getWebcams().get(cameraId);
    UtilWebcamCapture.adjustResolution(webcam, 640, 480);
    webcam.open();

    Dimension d = webcam.getDevice().getResolution();
    int imageWidth = d.width;
    int imageHeight = d.height;

    ConfigPolygonDetector config = new ConfigPolygonDetector(4);
    config.configRefineLines.sampleRadius = 2;
    config.configRefineLines.maxIterations = 30;

    InputToBinary<ImageFloat32> inputToBinary =
        FactoryThresholdBinary.globalOtsu(0, 255, true, ImageFloat32.class);
    //				FactoryThresholdBinary.globalEntropy(0,255,true,ImageFloat32.class);
    //				FactoryThresholdBinary.adaptiveSquare(10,0,true,ImageFloat32.class);
    BinaryPolygonConvexDetector<ImageFloat32> detector =
        FactoryShapeDetector.polygon(
            inputToBinary, new ConfigPolygonDetector(4), ImageFloat32.class);

    ImageFloat32 gray = new ImageFloat32(imageWidth, imageHeight);
    ImagePanel gui = new ImagePanel(imageWidth, imageHeight);
    ShowImages.showWindow(gui, "Fiducials", true);

    while (true) {
      BufferedImage frame = webcam.getImage();

      ConvertBufferedImage.convertFrom(frame, gray);

      detector.process(gray);

      // display the results
      Graphics2D g2 = frame.createGraphics();

      List<Polygon2D_F64> shapes = detector.getFound().toList();

      g2.setStroke(new BasicStroke(4));
      g2.setColor(Color.RED);
      g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
      g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      Line2D.Double l = new Line2D.Double();

      for (int i = 0; i < shapes.size(); i++) {
        Polygon2D_F64 poly = shapes.get(i);

        for (int j = 0; j < poly.size(); j++) {
          int k = (j + 1) % poly.size();

          l.setLine(poly.get(j).x, poly.get(j).y, poly.get(k).x, poly.get(k).y);
          g2.draw(l);
        }
      }

      gui.setBufferedImageSafe(frame);
      gui.repaint();
    }
  }