private void loadGUI() {
    setTitle("Chroma Key Sample");

    panelBottom = new JPanel();

    ButtonHandler l_buttonHandler = new ButtonHandler();
    buttonCaptureBackground = new JButton("Capture Background");
    buttonStart = new JButton("Start");
    buttonStart.setEnabled(false);
    buttonCaptureBackground.addActionListener(l_buttonHandler);
    buttonStart.addActionListener(l_buttonHandler);

    sliderColorRange = new JSlider(JSlider.HORIZONTAL, 0, 50, 30);
    sliderColorRange.setMinorTickSpacing(1);
    sliderColorRange.setPaintTicks(true);
    sliderColorRange.addChangeListener(new SliderHandler());

    labelColorRange = new JLabel("Color Range");

    panelSlider = new JPanel();
    panelSlider.add(labelColorRange);
    panelSlider.add(sliderColorRange);

    panelBottom.add(buttonCaptureBackground);
    panelBottom.add(buttonStart);

    Container l_container = getContentPane();
    l_container.setLayout(new BorderLayout());
    l_container.add(videoPanel, BorderLayout.NORTH);
    l_container.add(panelSlider, BorderLayout.CENTER);
    l_container.add(panelBottom, BorderLayout.SOUTH);

    setSize(videoInterface.getImageWidth(), videoInterface.getImageHeight() + 100);
    setVisible(true);
  }
  public ChromaKey() {
    try {
      videoPanel = new MarvinImagePanel();
      videoInterface = new MarvinJavaCVAdapter();
      videoInterface.connect(1);

      imageWidth = videoInterface.getImageWidth();
      imageHeight = videoInterface.getImageHeight();

      imageOut = new MarvinImage(imageWidth, imageHeight);

      loadGUI();

      pluginChroma = MarvinPluginLoader.loadImagePlugin("org.marvinproject.image.subtract.jar");
      pluginCombine =
          MarvinPluginLoader.loadImagePlugin("org.marvinproject.image.combine.combineByMask.jar");

      MarvinImage l_imageParadise = MarvinImageIO.loadImage("./res/paradise.jpg");
      Integer cameraWidth = videoInterface.getImageWidth();
      Integer cameraHeight = videoInterface.getImageHeight();

      MarvinImagePlugin pluginScale =
          MarvinPluginLoader.loadImagePlugin("org.marvinproject.image.transform.scale.jar");
      pluginScale.setAttribute("newWidth", cameraWidth);
      pluginScale.setAttribute("newHeight", cameraHeight);

      MarvinImage l_imageParadiseResize = new MarvinImage(1, 1);
      pluginScale.process(l_imageParadise, l_imageParadiseResize);
      l_imageParadise = l_imageParadiseResize;

      pluginCombine.setAttribute("combinationImage", l_imageParadise);
      pluginCombine.setAttribute("colorMask", new Color(0, 0, 255));

      imageBackground = new MarvinImage(cameraWidth, cameraHeight);

      thread = new Thread(this);
      thread.start();
      playing = true;
      removeBackground = false;
    } catch (MarvinVideoInterfaceException e) {
      e.printStackTrace();
    }
  }
  public void run() {
    try {
      while (true) {
        if (playing) {
          imageIn = videoInterface.getFrame();
          MarvinImage.copyColorArray(imageIn, imageOut);

          if (removeBackground) {
            pluginChroma.setAttribute("colorRange", colorRange);
            pluginChroma.process(imageIn, imageOut);
            pluginCombine.process(imageOut, imageOut);
          } else {
            MarvinImage.copyColorArray(imageIn, imageOut);
          }
          videoPanel.setImage(imageOut);
        }
      }
    } catch (MarvinVideoInterfaceException e) {
      e.printStackTrace();
    }
  }