Пример #1
0
  @Override
  @SuppressWarnings("unchecked")
  public void perform(InputSocket<?>[] inputs, OutputSocket<?>[] outputs, Optional<?> data) {
    final Mat input = ((InputSocket<Mat>) inputs[0]).getValue().get();
    final Mat tmp = ((Optional<Mat>) data).get();
    final boolean externalOnly = ((InputSocket<Boolean>) inputs[1]).getValue().get();

    if (input.empty()) {
      return;
    }

    // findContours modifies its input, so we pass it a temporary copy of the input image
    input.copyTo(tmp);

    // OpenCV has a few different things it can return from findContours, but for now we only use
    // EXTERNAL and LIST.
    // The other ones involve hierarchies of contours, which might be useful in some situations, but
    // probably only
    // when processing the contours manually in code (so, not in a graphical pipeline).
    MatVector contours = new MatVector();
    findContours(
        tmp, contours, externalOnly ? CV_RETR_EXTERNAL : CV_RETR_LIST, CV_CHAIN_APPROX_TC89_KCOS);

    final OutputSocket<ContoursReport> contoursSocket = (OutputSocket<ContoursReport>) outputs[0];
    contoursSocket.setValue(new ContoursReport(contours, input.rows(), input.cols()));
  }
Пример #2
0
  private int classify(final Mat f, final Boolean isChinses, final Boolean isSpeci) {
    int result = -1;
    Mat output = new Mat(1, numAll, CV_32FC1);

    ann.predict(f, output);

    int ann_min = (!isChinses) ? ((isSpeci) ? 10 : 0) : numCharacter;
    int ann_max = (!isChinses) ? numCharacter : numAll;

    float maxVal = -2;

    for (int j = ann_min; j < ann_max; j++) {
      float val = Convert.toFloat(output.ptr(0, j));

      if (val > maxVal) {
        maxVal = val;
        result = j;
      }
    }

    return result;
  }
Пример #3
0
  public static void main(String[] args) {
    Mat pFrame = imread("image0.png", CV_LOAD_IMAGE_GRAYSCALE);
    Mat cFrame = imread("image1.png", CV_LOAD_IMAGE_GRAYSCALE);
    Mat pGray = new Mat();
    Mat cGray = new Mat();

    pFrame.convertTo(pGray, CV_32FC1);
    cFrame.convertTo(cGray, CV_32FC1);
    Mat Optical_Flow = new Mat();

    DenseOpticalFlow tvl1 = createOptFlow_DualTVL1();
    tvl1.calc(pGray, cGray, Optical_Flow);

    Mat OF = new Mat(pGray.rows(), pGray.cols(), CV_32FC1);
    FloatBuffer in = Optical_Flow.getFloatBuffer();
    FloatBuffer out = OF.getFloatBuffer();

    int height = pGray.rows();
    int width = pGray.cols();

    for (int y = 0; y < height; y++) {
      for (int x = 0; x < width; x++) {
        float xVelocity = in.get();
        float yVelocity = in.get();
        float pixelVelocity = (float) Math.sqrt(xVelocity * xVelocity + yVelocity * yVelocity);
        out.put(pixelVelocity);
      }
    }
    imwrite("OF.png", OF);
  }