Example #1
0
  @Override
  public List<Frame> execute(CVParticle particle) throws Exception {
    List<Frame> result = new ArrayList<Frame>();
    if (!(particle instanceof Frame)) return result;

    Frame frame = (Frame) particle;
    BufferedImage image = frame.getImage();
    if (image == null) return result;
    if (image.getWidth() < 2 * cols || image.getHeight() < 2 * rows) return result;

    int width = image.getWidth() / cols;
    int height = image.getHeight() / rows;
    int tileIndex = 0;
    for (int r = 0; r < rows; r++) {
      for (int c = 0; c < cols; c++) {
        Rectangle box =
            new Rectangle(c * width, r * height, width + pixelOverlap, height + pixelOverlap);
        box = box.intersection(frame.getBoundingBox());
        BufferedImage tile = image.getSubimage(box.x, box.y, box.width, box.height);
        byte[] buffer = ImageUtils.imageToBytes(tile, imageType);
        result.add(
            new Frame(
                frame.getStreamId() + "_" + tileIndex,
                frame.getSequenceNr(),
                imageType,
                buffer,
                frame.getTimestamp(),
                box));
        tileIndex++;
      }
    }
    return result;
  }
Example #2
0
  @Override
  public List<Frame> execute(List<CVParticle> input) throws Exception {
    Frame frame = null;
    List<Feature> features = new ArrayList<Feature>();
    for (CVParticle particle : input) {
      if (particle instanceof Feature) {
        features.add((Feature) particle);
      } else if (particle instanceof Frame && frame == null) {
        frame = (Frame) particle;
      }
    }
    if (frame == null)
      frame =
          new Frame(
              input.get(0).getStreamId(),
              input.get(0).getSequenceNr(),
              Frame.NO_IMAGE,
              (byte[]) null,
              0L,
              new Rectangle());

    // merge new features with already existing features in the Frame
    f1:
    for (Feature newF : features) {
      for (Feature oldF : frame.getFeatures()) {
        if (newF.getName().equals(oldF.getName())) {
          oldF.getSparseDescriptors().addAll(newF.getSparseDescriptors());
          continue f1;
        }
      }
      frame.getFeatures().add(newF);
    }
    List<Frame> result = new ArrayList<Frame>();
    result.add(frame);
    return result;
  }