예제 #1
0
  public static void stop() {
    try {

      Thread.sleep(5000);
      FrameGrabbingControl fgc =
          (FrameGrabbingControl) player.getControl("javax.media.control.FrameGrabbingControl");

      Buffer buf = fgc.grabFrame();

      BufferToImage btoi = new BufferToImage((VideoFormat) buf.getFormat());
      player.stop();
      Image img = btoi.createImage(buf);

      int w = img.getWidth(null);

      int h = img.getHeight(null);

      BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);

      Graphics2D g2 = bi.createGraphics();

      g2.drawImage(img, 0, 0, null);

      g2.dispose();
      try {
        ImageIO.write(bi, "jpg", new File("C:/ii.jpg"));

      } catch (IOException ex) {
        Logger.getLogger(Capture_video.class.getName()).log(Level.SEVERE, null, ex);
      }
    } catch (InterruptedException ex) {
      Logger.getLogger(Capture_video.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
  public void captureImage() {
    String savepath =
        this.saveDirectory + "\\cam" + this.getDateFormatNow("yyyyMMdd_HHmmss-S") + ".jpg";
    System.out.println("Capturing current image to " + savepath);

    // Grab a frame
    FrameGrabbingControl fgc =
        (FrameGrabbingControl) player.getControl("javax.media.control.FrameGrabbingControl");
    buf = fgc.grabFrame();

    // Convert it to an image
    btoi = new BufferToImage((VideoFormat) buf.getFormat());
    img = btoi.createImage(buf);

    // save image
    saveJPG(img, savepath);

    // show the image
    // imgpanel.setImage(img);

    // images.add(img);
    images.add(savepath);

    if (images_lastadded.size() >= lastadded_max) {
      // Remove last
      images_lastadded.remove(images_lastadded.size() - 1);
    }

    images_lastadded.add(0, images.size() - 1);
    images_nevershown.add(0, images.size() - 1);

    forceNewImage();
  }
예제 #3
0
파일: JAIEffect.java 프로젝트: elecnix/jmf
  public int process(Buffer inBuffer, Buffer outBuffer) {
    try {
      if (frameConverter == null) {
        frameConverter = new BufferToImage((VideoFormat) inBuffer.getFormat());
      }

      // Convert the Buffer to an AWT Image.
      Image frameImage = frameConverter.createImage(inBuffer);

      // Derive a JAI image from the AWT image.
      PlanarImage jaiImage = JAI.create("AWTImage", frameImage);

      int index;
      boolean emboss = false;
      if (control != null) {
        index = control.getEffectIndex();
        if (control.getEffectName().equals("None")) {
          outBuffer.setData(inBuffer.getData());
          outBuffer.setFormat(inBuffer.getFormat());
          outBuffer.setFlags(inBuffer.getFlags());
          outBuffer.setLength(inBuffer.getLength());
          return BUFFER_PROCESSED_OK;
        }
        if (control.getEffectName().equals("Emboss")) {
          emboss = true; // Special case
        }
      } else index = 0;

      if (kernels[index] == null) {
        kernels[index] = new KernelJAI(3, 3, matrices[index]);
      }

      jaiImage = JAI.create("convolve", jaiImage, kernels[index]);

      if (emboss) { // add 128 to make it brighter
        double[] constants = new double[] {128., 128., 128.};
        ParameterBlock pb = new ParameterBlock();
        pb.addSource(jaiImage);
        pb.add(constants);
        jaiImage = JAI.create("addconst", pb, null);
      }

      // Now convert the image to a buffer
      BufferedImage bim = jaiImage.getAsBufferedImage();

      Buffer out = ImageToBuffer.createBuffer(bim, 15.F);
      if (out == null) {
        if (debug) {
          System.out.println("ImageToBuffer returned null");
        }
        return BUFFER_PROCESSED_FAILED;
      }

      outBuffer.setData(out.getData());
      outBuffer.setFormat(out.getFormat());
      outBuffer.setFlags(out.getFlags());
      outBuffer.setLength(out.getLength());
    } catch (Exception e) {
      System.err.println(e);
      return BUFFER_PROCESSED_FAILED;
    } catch (Error e) {
      System.err.println(e);
      return BUFFER_PROCESSED_FAILED;
    }
    return BUFFER_PROCESSED_OK;
  }
예제 #4
0
파일: JMFMovie.java 프로젝트: jfim/OpenCVP
 @Override
 public byte[] getFrameData() {
   Buffer buffer = frameGrabbingControl.grabFrame();
   BufferedImage image = (BufferedImage) imageConverter.createImage(buffer);
   return null;
 }