?
Solved

web cam code

Posted on 2004-11-24
14
Medium Priority
?
290 Views
Last Modified: 2011-08-18
Hello experts,
I have this bit of code that i found here:

http://java.sun.com/dev/evangcentral/totallytech/jmf.html

I would like to use it to try to learn how to use a web cam within my site..
thanks.
0
Comment
Question by:kephillips
  • 6
  • 6
12 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 12665088
What's the question
0
 

Author Comment

by:kephillips
ID: 12665384
oh sorry. How do I get this piece of code to work.
What type of file do I create, what do I need to add at the beginning and end of the code etc...
Thanks.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12666131
Did you download the zip file mentioned in the article?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:kephillips
ID: 12666669
yes, and it's just three files:

FrameGrabber.java
FrameGrabberExceptions.java
video.properties
 
I've tried running them and nothing....
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12666892
>> I've tried running them and nothing....
What errors/messages?
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12666930
And as you can read on that page:
"In addition to the standard Java Development Kit (JDK), a separate, platform-specific performance pack is required for the JMF API."
Did you installed that one?
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12666941
0
 

Author Comment

by:kephillips
ID: 12668239
yes i have looked at those places but can't seem to find anything for mac os X
0
 

Author Comment

by:kephillips
ID: 12670151
ok. it seems i have updated my java (downloaded from apple). Now it still doesn't do anything.
NO errors...just nothing...
0
 

Author Comment

by:kephillips
ID: 12696668
ok.
experts, I have a bit of code that I would like to test out. How do I embed this into a web page?????
THanks



public void printRGBDevices() {

   /*  Create a new default RGB format object (see the JMF documentation

    *  for other supported formats)

    */

   RGBformat rgbFormat = new RGBFormat();

 

   /*  Use the Format object to retrieve a Vector of CaptureDeviceInfo

    *  objects from the CaptureDeviceManager

    */

   Vector videoDevs = CaptureDeviceManager.getDeviceList(rgbFormat);

 

   /*  Loop through the results and print them out for the user  */

   for (int i = 0; i

 
   /*  We are looking for a format of 160 x 120 pixels with 24 bit

    *  colour depth, RGB

    */

   Dimension wantRes = new Dimension(160, 120);

   int wantDepth = 24;

 

 

   /*  Get the Formats supported by the device. (Real code will check for

    *  a null from getDevice)

    */

   CaptureDeviceInfo device = CaptureDeviceManager.getDevice("webcam:0");

   Format[] fmts = device.getFormats();

   RGBFormat userFormat = null;

 

   for (int i = 0; i
 
   MediaLocator loc = device.getLocator();

   DataSource formattedSource = null;

 

   try {

     formattedSource = Manager.createDataSource(loc);

   } catch (IOException ioe) {

     System.out.println("IO Error creating dataSource");

     System.exit(1);

   } catch (NoDataSourceException ndse) {

     System.out.println("Unable to create dataSource");

     System.exit(1);

   }

 

   /*  Setting the format is rather complicated. Firstly we need to get

    *  the format controls from the dataSource we just created. In order

    *  to do this we need a reference to an object implementing the

    *  CaptureDevice interface (which DataSource objects can).

    */

   if (!(formattedSource instanceof CaptureDevice)) {

     System.out.println("DataSource not a CaptureDevice");

     System.exit(1);

   }

 

   FormatControl[] fmtControls =

     ((CaptureDevice)formattedSource).getFormatControls();

 

   if (fmtControls == null || fmtControls.length == 0) {

     System.out.println("No FormatControl available");

     System.exit(1);

   }

 

   Format setFormat = null;

 

   /*  Now we need to loop through the available FormatControls and try

    *  to set the format to the one we want. According to the documentation

    *  even though this may appear to work, it may fail later on. Since

    *  we know that the format is supported we hope that this won't happen

    */

   for (int i = 0; i

 
 Object stateLock = new Object();  //  This must be a global

 

   //  Method code

 

   Processor deviceProc = null;

 

   try {

     deviceProc = Manager.createProcessor(formattedSource);

   } catch (IOException ioe) {

     System.out.println("Unable to get Processor for device: " +

       ioe.getMessage());

     System.exit(1);

   } catch (NoProcessorException npe) {

     System.out.println("Unable to get Processor for device: " +

       npe.getMessage());

     System.exit(1);

   }

 

   /*  In order to use the controller we have to put it in the realized

    *  state. We do this by calling the realize method, but this will

    *  return immediately so we must register a listener (this class) to

    *  be notified when the controller is ready. The class containing this

    *  code must implement the ControllerListener interface.

    */

   deviceProc.addControllerListener(this);

   deviceProc.realize();

   while (deviceProc.getState() != Controller.Realized) {

     synchronized (stateLock) {

       try {

         stateLock.wait();

       } catch (InterruptedException ie) {

         System.out.println("Device failed to get to realized state");

         System.exit(1);

       }

     }

   }

 

   /*  Finally, start the processor  */

   deviceProc.start();

 
 /**

  *  The ControllerListener interface only contains one method,

  *  controllerUpdate

  **/

 public void controllerUpdate(ControllerEvent ce) {

   if (ce instanceof RealizeCompleteEvent) {

     System.out.println("Realize transition completed");

 

     synchronized (stateLock) {

       stateLock.notifyAll();

     }

   }

 }

 




 
 private PushBufferStream camStream;  //  Global variable

 private BufferToImage converter;     //  Global variable

 

 

   //  Method code

 

   PushBufferDataSource source = null;

 

   try {

     source = (PushBufferDataSource)deviceProc.getDataOutput();

   } catch (NotRealizedError nre) {

     /*  Should never happen  */

     throw new VisionJMFException("Internal error: processor not realized");

   }

 

   /*  getStreams returns all available streams. For frame grabbing this

    *  is usually only one, but we need to check, just in case

    */

   PushBufferStream[] streams = source.getStreams();

 

   /*  Pick the first RGBFormat stream available (shouldn't be more than

    *  one)

    */

   for (int i = 0; i

 
   /**

    *  Get an image from the camera

    **/

   public Image getImage() {

     Buffer b = new Buffer();

 

     try {

       camStream.read(b);

     } catch (IOException ioe) {

       System.out.println("Unable to capture frame from camera");

       return null;

     }

 

     Image i = converter.createImage(b);

     return i;

   }

 
0
 

Author Comment

by:kephillips
ID: 12707918
how do i get a .java page (like the script above) to work within an html page???
0
 
LVL 37

Accepted Solution

by:
zzynx earned 2000 total points
ID: 12713664
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month17 days, 5 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question