WEB-CAMM picture capturing

Discussion in 'Java' started by azsx, Aug 16, 2006.

  1. azsx

    azsx Guest

    Can someone tell how can I use Java to capture some webcamm data?
    azsx, Aug 16, 2006
    #1
    1. Advertising

  2. azsx

    Oliver Wong Guest

    "azsx" <> wrote in message
    news:...
    > Can someone tell how can I use Java to capture some webcamm data?
    >


    When I google for "Java webcamm", Google asks me if I meant "Java
    webcam", and when I say yes, I get
    http://www.surveyor.com/support/webcam32help/java.html

    - Oliver
    Oliver Wong, Aug 16, 2006
    #2
    1. Advertising

  3. azsx

    Dag Sunde Guest

    azsx wrote:
    > Can someone tell how can I use Java to capture some webcamm data?



    Take a look at "Java Media Framework API (JMF)"
    (See here: http://java.sun.com/products/java-media/jmf/index.jsp)


    Below is a sample that works ok with my 10$ camera...:

    //------------------------------------
    import java.io.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.image.*;
    import javax.imageio.*;
    import javax.media.*;
    import javax.media.control.*;
    import javax.media.format.*;
    import javax.media.util.*;


    /**
    * Grabs a frame from a Webcam, overlays the current date and time,
    * and saves the frame as a PNG to c:\webcam.png
    *
    * @author David
    * @version 1.0, 16/01/2004
    */
    public class FrameGrab
    {
    public static void main(String[] args) throws Exception
    {
    // Create capture device
    CaptureDeviceInfo deviceInfo = CaptureDeviceManager.getDevice(
    "vfw:Microsoft WDM Image Capture (Win32):0");

    Player player = Manager.createRealizedPlayer(deviceInfo.getLocator());
    player.start();

    // Wait a few seconds for camera to initialise (otherwise img==null)
    Thread.sleep(2500);

    // Grab a frame from the capture device
    FrameGrabbingControl frameGrabber =
    (FrameGrabbingControl)player.getControl(
    "javax.media.control.FrameGrabbingControl");

    Buffer buf = frameGrabber.grabFrame();

    // Convert frame to an buffered image so it can be processed and saved
    Image img = (new
    BufferToImage((VideoFormat)buf.getFormat()).createImage(buf));
    BufferedImage buffImg = new BufferedImage(img.getWidth(null),
    img.getHeight(null), BufferedImage.TYPE_INT_RGB);

    Graphics2D g = buffImg.createGraphics();
    g.drawImage(img, null, null);

    // Overlay curent time on image
    g.setColor(Color.RED);
    g.setFont(new Font("Verdana", Font.BOLD, 16));
    g.drawString((new Date()).toString(), 10, 25);

    // Save image to disk as PNG
    ImageIO.write(buffImg, "jpg", new File(
    "d:\\javaProjects\\capture\\src\\webcam.jpg"));

    // Stop using webcam
    player.close();
    player.deallocate();
    System.exit(0);
    }
    }
    //------------------------------------

    --
    Dag.
    Dag Sunde, Aug 17, 2006
    #3
  4. azsx

    azsx Guest

    Thanks. Now I have another issue: how can I transmit web-camera data
    via a network or Internet???
    azsx, Aug 17, 2006
    #4
  5. azsx

    Dag Sunde Guest

    azsx wrote:
    > Thanks. Now I have another issue: how can I transmit web-camera data
    > via a network or Internet???


    Live?
    Read the API doc and samples at the link I posted.
    The word you're looking for is probably "Streaming"

    But if you mean how to publish a static picture out
    on a web-server or another network machine after you grabbed
    it, its only a question of copying it, POSTing it via http,
    FTP it or whatever means you find convenient.

    --
    Dag.
    Dag Sunde, Aug 18, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alvin Bruney
    Replies:
    2
    Views:
    428
    Neil Kimber
    Jul 21, 2003
  2. jm
    Replies:
    4
    Views:
    570
    GIMME
    Jan 6, 2004
  3. Giulio Cespuglio
    Replies:
    7
    Views:
    329
    John Hunter
    Nov 27, 2003
  4. B. Chernick
    Replies:
    7
    Views:
    321
    B. Chernick
    Jun 25, 2008
  5. Replies:
    8
    Views:
    1,248
    Mick White
    Apr 19, 2005
Loading...

Share This Page