Google Answers Logo
View Question
Q: Extracting Still Pictures from iSight camera using Java on Mac OS X ( Answered,   1 Comment )
Subject: Extracting Still Pictures from iSight camera using Java on Mac OS X
Category: Computers > Programming
Asked by: ericb01-ga
List Price: $25.00
Posted: 09 Sep 2004 04:38 PDT
Expires: 09 Oct 2004 04:38 PDT
Question ID: 398810
Is there a way to programmatically extract still pictures from the
Apple iSight Firewire camera using the Java programming language on
the Mac OS X platform (more specifically PowerBook G4)?  If so, how? 
Sample Code?

Request for Question Clarification by googleexpert-ga on 09 Sep 2004 07:28 PDT
Yes, there certainly seems to be a way to extract still pictures from
iSight using Java.

Although which version of Java and OS X you're using might be an issue.

Which version of Java and OS X will you be using this Java program?



Clarification of Question by ericb01-ga on 09 Sep 2004 09:44 PDT
Hi GoogleExpert,

My operating system is: 10.3.5

My version of java is 1.4.2

java version "1.4.2_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_05-141)
Java HotSpot(TM) Client VM (build 1.4.2-38, mixed mode)

Hope this helps,

Request for Question Clarification by googleexpert-ga on 09 Sep 2004 22:28 PDT
Hi Eric,
I found sample code and compiled the Java code.
I ran into a problem.

Problem: No iSight Camera to test code against.

I would like to know if you want the sample code and
if that qualifies as an answer to your question.

Clarification of Question by ericb01-ga on 10 Sep 2004 05:26 PDT
Is it possible for you to share the compiled Java classes with me and
I can test it with my iSight camera before I mark this question as

My objective is to incorporate the Java code into a larger specialized
system so I will definitely need the source code.

If the compiled Java classes work for me, then I can answer this
question as answered and then you can give me the actual Java source
Is that acceptable?

Request for Question Clarification by googleexpert-ga on 10 Sep 2004 06:12 PDT
Here's what I found.

First, copy and unzip /System/Library/Java/Extensions/ to your
testing  directory to bypass any classpath issues.

Source code for the VideoCapture class
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
import java.awt.image.WritableRaster;
import quicktime.QTRuntimeException;
import quicktime.QTRuntimeHandler;
import quicktime.QTSession;
import quicktime.qd.PixMap;
import quicktime.qd.QDConstants;
import quicktime.qd.QDGraphics;
import quicktime.qd.QDRect;
import quicktime.std.StdQTConstants;
import quicktime.util.RawEncodedImage;

public class VideoCapture {
    private SequenceGrabber grabber;
    private SGVideoChannel channel;
    private RawEncodedImage rowEncodedImage;

    private int width;
    private int height;
    private int videoWidth;

    private int[] pixels;
    private BufferedImage image;
    private WritableRaster raster;

    public VideoCapture(int width, int height) throws Exception {
        this.width = width;
        this.height = height;
        try {
            QDRect bounds = new QDRect(width, height);
            QDGraphics graphics = new QDGraphics(bounds);
            grabber = new SequenceGrabber();
            grabber.setGWorld(graphics, null);
            channel = new SGVideoChannel(grabber);
            grabber.prepare(true, false);
            PixMap pixMap = graphics.getPixMap();
            rowEncodedImage = pixMap.getPixelData();

            videoWidth = width + (rowEncodedImage.getRowBytes() - width * 4) / 4;
            pixels = new int[videoWidth * height];
            image = new BufferedImage(
                videoWidth, height, BufferedImage.TYPE_INT_RGB);
            raster = WritableRaster.createPackedRaster(DataBuffer.TYPE_INT,
                videoWidth, height,
                new int[] { 0x00ff0000, 0x0000ff00, 0x000000ff }, null);
            raster.setDataElements(0, 0, videoWidth, height, pixels);
            QTRuntimeException.registerHandler(new QTRuntimeHandler() {
                public void exceptionOccurred(
                        QTRuntimeException e, Object eGenerator,
                        String methodNameIfKnown, boolean unrecoverableFlag) {
                    System.out.println("what should i do?");
        } catch (Exception e) {
            throw e;

    public void dispose() {
        try {
        } catch (Exception e) {
        } finally {

    public int getWidth() {
        return width;

    public int getHeight() {
        return height;

    public int getVideoWidth() {
        return videoWidth;

    public int getVideoHeight() {
        return height;

    public void getNextPixels(int[] pixels) throws Exception {
        rowEncodedImage.copyToArray(0, pixels, 0, pixels.length);

    public Image getNextImage() throws Exception {
        rowEncodedImage.copyToArray(0, pixels, 0, pixels.length);
        raster.setDataElements(0, 0, videoWidth, height, pixels);
        return image;

I also found pages that merely serve as possible reference guides:
Note: had trouble compiling, probably needed the entire ImageJ package.
Login/Password: archives/archives

Please let me know if you have any problems compiling.


Request for Question Clarification by googleexpert-ga on 13 Sep 2004 15:54 PDT
Hi ericb01,
I would like to know if the java sources worked for you.
Please let me know if you need any help.



Clarification of Question by ericb01-ga on 13 Sep 2004 18:01 PDT
Sorry I didn't get a chance to get back to you sooner.  Yes, the code
worked.  There is a configuration window that pops up to let me change
the settings of the camera.

Have you any idea which line of code controls that functionality so I
can optionally display this configuration window?  If not, I suppose
my question is answered.

I have another question about capturing sound from an iSight camera. 
Not sure if that was convered on the website you referenced.

Subject: Re: Extracting Still Pictures from iSight camera using Java on Mac OS X
Answered By: googleexpert-ga on 13 Sep 2004 19:48 PDT
Thanks for getting back to me and for informing me of the working code.

About your popup configuration window, I believe commenting or taking
out the following line will not display a popup window:
/**** function for iSight Popup window 


Now, about capturing sound with Java, here's what I found(source code included):

Capturing Audio with Java Sound API:

Java Sound, Getting Started, Part 2, Capture Using Specified Mixer:

Java Sound Resources: Examples: Audio Playback and Recording:

I hope that helps you.

If you have anymore questions, please don't hesitate to ask me.

Thanks again.


Clarification of Answer by googleexpert-ga on 13 Sep 2004 20:08 PDT
[search strategy]

"import java" isight
Subject: Re: Extracting Still Pictures from iSight camera using Java on Mac OS X
From: tjbates-ga on 30 Jan 2005 09:09 PST
I am doing a final year project and was interested by this technique
of image capture and was wondering if you have had any luck getting it
to work?

I am trying to capture images from iSight convert to binary image then
input the data to an Multi-Layer Perceptron for anaysis and hopefully
it will return a output comparible to the input image. e.g. a picture
of an apple is shown to iSight and the MLP will look at the shape and
say its an apple.

If you managed to capute images from iSight i would be graful if you
could let me know how you did it and if you have any source that would
help me considerably.


Tom Bates

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  

Google Home - Answers FAQ - Terms of Service - Privacy Policy