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?
Thanks
-googleexpert
|
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,
Eric
|
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
answered?
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
files.
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/QTJava.zip 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.std.sg.SequenceGrabber;
import quicktime.std.sg.SGVideoChannel;
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 {
QTSession.open();
QDRect bounds = new QDRect(width, height);
QDGraphics graphics = new QDGraphics(bounds);
grabber = new SequenceGrabber();
grabber.setGWorld(graphics, null);
channel = new SGVideoChannel(grabber);
channel.setBounds(bounds);
channel.setUsage(StdQTConstants.seqGrabPreview);
channel.settingsDialog();
grabber.prepare(true, false);
grabber.startPreview();
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);
image.setData(raster);
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) {
QTSession.close();
throw e;
}
}
public void dispose() {
try {
grabber.stop();
grabber.release();
grabber.disposeChannel(channel);
image.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
QTSession.close();
}
}
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 {
grabber.idle();
rowEncodedImage.copyToArray(0, pixels, 0, pixels.length);
}
public Image getNextImage() throws Exception {
grabber.idle();
rowEncodedImage.copyToArray(0, pixels, 0, pixels.length);
raster.setDataElements(0, 0, videoWidth, height, pixels);
image.setData(raster);
return image;
}
}
URL: http://gogo.tea-nifty.com/interpot/java/
:
I also found pages that merely serve as possible reference guides:
http://rsb.info.nih.gov/ij/plugins/qt-capture.html
Note: had trouble compiling, probably needed the entire ImageJ package.
http://www.oreillynet.com/pub/wlg/2933
http://www.oreillynet.com/cs/user/view/cs_msg/40741
http://www.onjava.com/lpt/a/4318
http://lists.apple.com/archives/quicktime-java/2003/Dec/15/howtocropanimagecaptured.txt
Login/Password: archives/archives
Please let me know if you have any problems compiling.
-googleexpert
|
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.
Thanks.
-googleexpert
|
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.
Thanks,
Eric
|