コード例 #1
0
ファイル: SocketTest.java プロジェクト: JLLeitschuh/GRIP
  @Test
  public void testSocketPreview() {
    SocketHint<Number> sh = SocketHints.createNumberSocketHint("foo", 0);
    OutputSocket<Number> socket = new OutputSocketImpl<>(eventBus, sh);

    final boolean[] handled = new boolean[] {false};
    Object eventHandler =
        new Object() {
          @SuppressFBWarnings(
              value = "UMAC_UNCALLABLE_METHOD_OF_ANONYMOUS_CLASS",
              justification = "This method is called by Guava's EventBus")
          @Subscribe
          public void onSocketPreviewed(SocketPreviewChangedEvent e) {
            handled[0] = true;
            assertTrue(
                "A preview event fired for a socket but the socket was not labeled as able to "
                    + "be previewed",
                socket.isPreviewed());
          }
        };

    eventBus.register(eventHandler);
    socket.setPreviewed(true);
    eventBus.unregister(eventHandler);

    assertTrue("SocketPreviewChangedEvent was not received", handled[0]);
  }
コード例 #2
0
ファイル: FindContoursOperation.java プロジェクト: MeRPG/GRIP
  @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()));
  }
コード例 #3
0
ファイル: SocketTest.java プロジェクト: JLLeitschuh/GRIP
  @Test
  public void testSocketChangedEvent() throws Exception {
    final boolean[] handled = new boolean[] {false};
    final Double[] value = new Double[] {0.0};
    Object eventHandler =
        new Object() {
          @SuppressFBWarnings(
              value = "UMAC_UNCALLABLE_METHOD_OF_ANONYMOUS_CLASS",
              justification = "This method is called by Guava's EventBus")
          @Subscribe
          public void onSocketChanged(SocketChangedEvent e) {
            handled[0] = true;
            value[0] = (Double) socket.getValue().get();
          }
        };

    eventBus.register(eventHandler);
    socket.setValue(TEST_VALUE);
    eventBus.unregister(eventHandler);

    assertTrue(handled[0]);
    assertEquals(TEST_VALUE, value[0]);
  }
コード例 #4
0
ファイル: SocketTest.java プロジェクト: JLLeitschuh/GRIP
 @Test
 public void testDefaultValue() throws Exception {
   sh = SocketHints.Inputs.createNumberSliderSocketHint("foo", TEST_VALUE, 0.0, 1.0);
   socket = new OutputSocketImpl<>(eventBus, sh);
   assertEquals(TEST_VALUE, socket.getValue().get());
 }
コード例 #5
0
ファイル: SocketTest.java プロジェクト: JLLeitschuh/GRIP
 @Test
 public void testSetValue() throws Exception {
   socket.setValue(TEST_VALUE);
   assertEquals(TEST_VALUE, socket.getValue().get());
 }
コード例 #6
0
ファイル: SocketTest.java プロジェクト: JLLeitschuh/GRIP
 @Test
 public void testGetSocketHint() throws Exception {
   assertEquals("foo", socket.getSocketHint().getIdentifier());
   assertEquals(Number.class, socket.getSocketHint().getType());
   assertEquals(SocketHint.View.SLIDER, socket.getSocketHint().getView());
 }