Ejemplo n.º 1
0
  private void undoRadialDistortion(BufferedImage image) {
    ConvertBufferedImage.convertFromMulti(image, origMS, true, ImageFloat32.class);

    for (int i = 0; i < origMS.getNumBands(); i++) {
      ImageFloat32 in = origMS.getBand(i);
      ImageFloat32 out = correctedMS.getBand(i);

      undoRadial.apply(in, out);
    }
    if (correctedMS.getNumBands() == 3)
      ConvertBufferedImage.convertTo(correctedMS, undistorted, true);
    else if (correctedMS.getNumBands() == 1)
      ConvertBufferedImage.convertTo(correctedMS.getBand(0), undistorted);
    else throw new RuntimeException("What kind of image has " + correctedMS.getNumBands() + "???");
  }
Ejemplo n.º 2
0
  public void setSelected(int selected) {
    this.selectedImage = selected;
    this.isUndistorted = false;

    if (origMS == null) {
      BufferedImage image = images.get(selected);

      // the number of bands can be difficult to ascertain without digging deep into the data
      // structure
      // so just declare a new one using convert
      origMS = ConvertBufferedImage.convertFromMulti(image, null, true, ImageFloat32.class);
      correctedMS = ConvertBufferedImage.convertFromMulti(image, null, true, ImageFloat32.class);
      undistorted = new BufferedImage(image.getWidth(), image.getHeight(), image.getType());
    }
  }
Ejemplo n.º 3
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;
    }
  }
  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);
  }
Ejemplo n.º 6
0
  private void doNotScaleLayers() {
    int N = pyramid.getNumLayers();

    for (int i = 0; i < N; i++) {
      BufferedImage b = ConvertBufferedImage.convertTo(pyramid.getLayer(i), null, true);
      addImage(b, String.format("%5.2f", pyramid.getScale(i)));
    }
  }
  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;
  }
Ejemplo n.º 8
0
  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();
          }
        });
  }
Ejemplo n.º 9
0
  private void scaleUpLayers() {
    T l = pyramid.getLayer(0);
    if (upscale == null) {
      interp = (InterpolatePixelS<T>) FactoryInterpolation.nearestNeighborPixelS(l.getClass());
      upscale = (T) l._createNew(l.width, l.height);
    } else {
      upscale.reshape(l.width, l.height);
    }

    int N = pyramid.getNumLayers();

    for (int i = 0; i < N; i++) {
      new FDistort(pyramid.getLayer(i), upscale).interpNN().scaleExt().apply();
      BufferedImage b = ConvertBufferedImage.convertTo(upscale, null, true);
      if (showScales) addImage(b, String.format("%5.2f", pyramid.getScale(i)));
      else addImage(b, String.format("%5.2f", pyramid.getSigma(i)));
    }
  }
  public void process(final BufferedImage image) {
    imageInput.reshape(image.getWidth(), image.getHeight());
    imageBinary.reshape(image.getWidth(), image.getHeight());
    imageOutput.reshape(image.getWidth(), image.getHeight());

    ConvertBufferedImage.convertFromSingle(image, imageInput, imageType);

    final double threshold = GThresholdImageOps.computeOtsu(imageInput, 0, 255);
    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            selectThresh.setThreshold((int) threshold);
            setInputImage(image);
            selectThresh.getHistogramPanel().update(imageInput);
            selectThresh.repaint();
          }
        });
    doRefreshAll();
  }
  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();
  }
Ejemplo n.º 12
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();
    }
  }