Introduction
Before getting struck in a restless time period I determine to put my second post about Java Media Framework. In my previous post I’ve showed how to play audio and video files using this framework.
In this post I’m going to show you how to capture an image and how to record a video using webcam.
Capturing an image
First you need to get a list of devices with the help of CaptureDeviceManager and filter out the first element of that list. Then you can get the visual component of it and use it as the video screen.
Then you have to place all those player control panel and video screen on a frame. After that you allow the program to capture image after a certain time.
After that as in many cases Java has to treat the buffered image. You can save the image in any format you wish, with the help of ImageIO.
Here’s an example code on how to do that.
import java.awt.BorderLayout; import java.awt.Component; import java.awt.Frame; import java.awt.Graphics2D; import java.awt.Image; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.image.BufferedImage; import java.io.File; import java.util.Vector; import javax.imageio.ImageIO; import javax.media.*; import javax.media.control.FrameGrabbingControl; import javax.media.format.RGBFormat; import javax.media.format.VideoFormat; import javax.media.util.BufferToImage; /** * * @author BUDDHIMA */ public class WebCam { CaptureDeviceInfo device; MediaLocator ml; Player player; Component videoScreen; public static void main(String args[]) { new WebCam();// create a new instance of WebCam in main function } WebCam() { try { //gets a list of devices how support the given videoformat Vector deviceList = CaptureDeviceManager.getDeviceList(new RGBFormat()); System.out.println(deviceList.toString()); //gets the first device in deviceList device = (CaptureDeviceInfo) deviceList.firstElement(); ml = device.getLocator(); player = Manager.createRealizedPlayer(ml); player.start(); videoScreen = player.getVisualComponent(); Frame frm = new Frame(); frm.setBounds(10, 10, 900, 700);//sets the size of the screen // setting close operation to the frame frm.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { System.exit(0); } }); //place player and video screen on the frame frm.add(videoScreen, BorderLayout.CENTER); frm.add(player.getControlPanelComponent(), BorderLayout.SOUTH); frm.setVisible(true); //capture image Thread.sleep(10000);//wait 10 seconds before capturing photo FrameGrabbingControl fgc = (FrameGrabbingControl) player.getControl("javax.media.control.FrameGrabbingControl"); Buffer buf = fgc.grabFrame();//grab the current frame on video screen BufferToImage btoi = new BufferToImage((VideoFormat) buf.getFormat()); Image img = btoi.createImage(buf); saveImagetoFile(img, "MyPhoto.jpg");//save the captured image as MyPhoto.jpg } catch (Exception e) { System.out.println(e); } } private void saveImagetoFile(Image img, String string) { try { 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(); String fileType = string.substring(string.indexOf('.') + 1); ImageIO.write(bi, fileType, new File(string)); } catch (Exception e) { } } }
Record a video
Although this code is not functioning too well, you can capture some small video clips using this. I’ve to mention that captureing a video is not that much easy as capturing an image. You have to study about Processors and ProcessorModels in JMF to get the clear idea about that.
import java.util.Vector; import javax.media.*; import javax.media.format.AudioFormat; import javax.media.format.VideoFormat; import javax.media.protocol.DataSource; import javax.media.CaptureDeviceInfo; import javax.media.format.YUVFormat; import javax.media.protocol.FileTypeDescriptor; /** * * @author BUDDHIMA */ public class CamRecorder { static VideoFormat videoFormat; static AudioFormat audioFormat; static CaptureDeviceInfo videoDevice; static CaptureDeviceInfo audioDevice; public static void main(String[] args) { try { Vector deviceList = CaptureDeviceManager.getDeviceList(new YUVFormat()); //get all media devices CaptureDeviceInfo device = (CaptureDeviceInfo) deviceList.firstElement(); //in this computer the only capture device is in=built webcam stays at 0th position Format[] formats = device.getFormats(); //get all formats for (int x = 0; x < formats.length; x++) { if (formats[x] != null && formats[x] instanceof VideoFormat) { videoFormat = (VideoFormat) formats[x]; //take the video format videoDevice = device; } if (formats[x] != null && formats[x] instanceof AudioFormat) { audioFormat = (AudioFormat) formats[x]; //take the audio format //audioDevice = device; } } //create data sources DataSource videoDataSource = Manager.createDataSource(device.getLocator()); deviceList = CaptureDeviceManager.getDeviceList(new AudioFormat(null)); //get all media devices device = (CaptureDeviceInfo) deviceList.firstElement(); DataSource audioDataSource=Manager.createDataSource(device.getLocator()); DataSource[] dArray=new DataSource[2]; dArray[0]=videoDataSource; dArray[1]=audioDataSource; DataSource mixedDataSource = Manager.createMergingDataSource(dArray); //format for output Format[] outputFormats=new Format[2]; outputFormats[0]=new VideoFormat(VideoFormat.YUV); outputFormats[1]=new AudioFormat(AudioFormat.LINEAR); //output type FileTypeDescriptor outputType=new FileTypeDescriptor(FileTypeDescriptor.MSVIDEO); //settingup Processor ProcessorModel processorModel=new ProcessorModel(mixedDataSource, outputFormats, outputType); Processor processor=Manager.createRealizedProcessor(processorModel); //settingup sink DataSource outputDataSource=processor.getDataOutput(); MediaLocator destination=new MediaLocator("file:.\\testcam.avi"); DataSink dataSink=Manager.createDataSink(outputDataSource, destination); dataSink.open(); //start sink + processor Thread.sleep(4000); dataSink.start(); processor.start(); Thread.sleep(4000); dataSink.close(); processor.stop(); processor.close(); } catch (Exception ex) { } } }
Resources
1. JMF Architecture http://www.ibm.com/developerworks/java/tutorials/j-jmf/section4.html
2. http://www.javaworld.com/javaworld/jw-05-2001/jw-0504-jmf2.html?page=1
3. http://www.java-forums.org/new-java/40115-capturing-video-webcam-jmf.html
hi i have compiled the program Capturing Of Images but its showing the output as
[]
java.util.NoSuchElementException
Plz help me how to over come this error
Try out with the link given by Tharindu Dasun
please check this link
http://osama-oransa.blogspot.com/2010/12/capture-photo-from-web-cam-usb-cam.html
Thanks for sharing this valuable link. Hope this will solve problems , if someone has with the above method.
Can you explain the procedure to get the jar files to the netbeans.
First you have to download the appropriate .jar file
Then in Netbeans you can see Project window on left panel (If not go Windows -> Projects)
Expand the tree view of your Java project
Then right click on ” Libraries” folder and select “Add JAR/Folder …”
After that select the downloaded .jar folder.
Then at the beginning of your class (you wish to use those libraries) import these libraries.
That’s all . 🙂
First of all thank you so much for such an amazing program that you have shared with us…
I am facing the Same Problem as mentioned earlier…. I have compiled the above program but its showing me exception like :
[]
java.util.NoSuchElementException
Plz help me how to over come this error
I have gone through the link you have given but still not able to rectify the problem…Please Help me out….!!!!!!!!!!!
Buddhima Wijeweera,Can i have your email id plz ??? I have some More doubts…
Thank you for your appreciations.
You may face that problem (most probably) when your web cam doesn’t support for JMF .(JMF is a bit old one).
Also try by importing JMF library files to the project.
If it doesn’t work could you try the link
http://osama-oransa.blogspot.com/2010/12/capture-photo-from-web-cam-usb-cam.html
I’ll send you an email to the email you provided.
Did you over come this error? Because i get the same error and can’t figure out how to fix it!
As I heard some web cams do not support this JMF. But you can try another framework, it may work. ( Another one is mentioned in comments )
sweeti22 did you overcome the problem
dear buddhima wijeweera im geeting the same error as other nosuchelement error can u plz help me
Sherya,
As I said earlier cases, some cameras do not support JMF. Then you have to try another.
This page says another method (it’s also mentioned in previous comments also):
http://osama-oransa.blogspot.com/2010/12/capture-photo-from-web-cam-usb-cam.html
Some people who failed in JMF , have overcome through this.
If not, you can try on OpenCV (version for Java) http://ubaa.net/shared/processing/opencv/
But I haven’t experience. I have heard that OpenCV also use with C#,C,C++.
So I wish these may help you too….!
sir can u tel the camera that support the jmf
My one is integrated web cam (Creative) . It worked with the above code.
Hello Sir
I can Used your Code the the image is can not be see thear only blank screen see there pls help me
Not clear. Didn’t you get any errors ?
Hello SIr
I try your code but when we run your code there is nothing show in screen only black screen is show pls help me
C:\>javac WebCam.java
C:\>java WebCam
[vfw:Microsoft WDM Image Capture (Win32):0 : vfw://0
RGB, 320×240, Length=230400, 24-bit, Masks=3:2:1, PixelStride=3, LineStride=960,
Flipped
RGB, 160×120, Length=57600, 24-bit, Masks=3:2:1, PixelStride=3, LineStride=480,
Flipped
RGB, 176×144, Length=76032, 24-bit, Masks=3:2:1, PixelStride=3, LineStride=528,
Flipped
RGB, 352×288, Length=304128, 24-bit, Masks=3:2:1, PixelStride=3, LineStride=1056
, Flipped
RGB, 640×480, Length=921600, 24-bit, Masks=3:2:1, PixelStride=3, LineStride=1920
, Flipped
]
Hello Sir Whan i try your application i can see only pink screen
can you help me
Exception in thread “VFW Request Thread” java.lang.UnsatisfiedLinkError: JMFSecurityManager: java.lang.UnsatisfiedLinkError: C:\Windows\System32\jmvfw.dll: Can’t load IA 32-bit .dll on a AMD 64-bit platform
at com.sun.media.JMFSecurityManager.loadLibrary(JMFSecurityManager.java:206)
at com.sun.media.protocol.vfw.VFWCapture.(VFWCapture.java:19)
at com.sun.media.protocol.vfw.VFWSourceStream.doConnect(VFWSourceStream.java:241)
at com.sun.media.protocol.vfw.VFWSourceStream.run(VFWSourceStream.java:763)
at java.lang.Thread.run(Thread.java:619)
got tis error any help please thx
this works extremely good for me…
Thanks
Hy!
i would like to do it the same but grabbing the frame from a video stored in my pc. So i create the player from a data source:
p= Manager.createRealizedPlayer(ds);
i can watch the video but when i tried to grab the video the image is null:
Buffer bf=fgc.grabFrame();
BufferToImage bti = new BufferToImage((VideoFormat)bf.getFormat());
Image ima=bti.createImage(bf);
if (ima==null){
System.out.println(“bti null”);
System.exit(0);
}
I have used the sleep and this thing is driving me crazy! do you know what might be the problem?? can you try to do the same with a video stored in your pc??
do i need to set my classpath???
sorry for all those questions 🙂
Hai,
The Example code is very nice.And i had a problem.The java.media.*;package is not exist.So how to over come this problem.
please reply.
This is extremely very nice for me.
Thanks.
Hi Gnana,
For this example you need to install Java Media Framework. This is a continuation of my previous post “https://buddhimawijeweera.wordpress.com/2011/05/01/how-to-play-audio-and-video-files-in-java-applications/” , I didn’t mentioned about that here. 🙂
Thanks for your valuable post, please keep on posting such valuable posts.
I tried this application, but JMF is not showing any image capturing devices(my Intex USB web camera).
Could you please help in this issue of how to make sure that JMF detects my web camera, so that I can capture the image from video.
Hi Rasheed,
I’ve already mentioed that JMF does not support all the cameras. So could you try other options given in previous comments and following links:
JMF: http://fmj-sf.net/index.php
JavaCV
JMyron: http://webcamxtra.sourceforge.net/
Hope those will help you to find the solution !
hi, this is kiran from bangalore
i am working in a project
where the project tells that
we have to use java coding
and here i have used ur code….. its working very fine… thanks for posting it in the site…..
i just had a problem…….
can you please post me the code on same thing using applet
and in your code the capturing of the media data happens and it gets stored in a file called test.avi and if i need to record another video and and save it in an another file it doesnt happen in that way, can u help in this sort………. please post the required code to the above mail-id nagakiran5@in.com
thanking you
regards
Naga kiran kumar
Hi Kiran,
You are welcome
I haven’t done that yet. But after a bit of using Google I found following resources. Hope they will help you !
http://java.sys-con.com/node/45832
http://gemsres.com/photos/story/res/45832/source.html
http://www.mutong.com/fischer/java/usbcam/
http://www.oracle.com/technetwork/java/javase/index-135334.html
i am doing project on audio and video conferencing..so i need code.plz help me
Hi Pravin,
What sort of help do you want ?
when I run the programe webcam.java it does not giec the output…it gives me error as:java.util.NoSuchElementException… piz sir help me
Hi Jayashri,
This problem occurs mainly because your web cam does not support JMF. As I told in post JMF is a bit older framework and doesn’t support all web cams. Alternative approaches may be the solutions given in the comments above. Hope you will get solution through those.
Hi buddhima
[]
java.util.NoSuchElementException
this code doesn,t work my laptop inbuild web cam, is this not support laptop web cam???? help me
thnks…
Hi Sandaruwan,
Support for JMF depends on the type of the web cam. I tried this with my laptop inbuilt web cam and it worked. But some types of web cam may not support for JMF, if so you have to go with another solution. Some of them are mentioned in the previous comments.
hi. i’ve tried the code and it works, but i dont know how to capture the image then save it as .jpg or .jpeg file. help me…
thanks 🙂
Hi Ariyanti,
If you look at the code carefully you’ll notice that at line No.70, grabFrame() method is used to capture the current frame on camera (what is visible to the camera at that moment). Then it creates a BufferedToImage object. By using saveImagetoFile method you can save the file with .jpg,png or gif format (http://docs.oracle.com/javase/tutorial/2d/images/saveimage.html).
Only thing you have to do is replace “MyPhoto.jpg” with the name you wish to see. (eg: Abc.png).
Hope you got the answer 🙂
actually i dont know where the capture button when i run the program.. 😦
regarding about this i can help u. mail to this id nagakiran5@in.com about your problem, because i have worked my project in this technology regarding capturing video only.
this comment which i am passing is for all people who wants to know how the video can be recorded using the JMF…. u can to the above mail id which i have mentioned in the comment
Hi Naga Kiran,
Thanks for come and trying to help. But I think the problem is about capturing an image.
It’s also better if you can share your experience about capturing video here, so it would help others.
🙂
Hi Ariyanti,
In this code you won’t get a button. grabFrame() captures the frame. In this code it waits 10 seconds (code:Thread.sleep(10000);) before capture.
You can add a button and insert grabFrame() method, so you can capture images when you click it. But rest of the program must need a change in flow.
Hope you got the answer now 🙂
http://www.invertedsoftware.com/tutorials/Record-Movies-with-Java-Media-Framework-JMF.html
i think this link will help you. try with this let us discuss the capturing of image later.
this link will help you totally how to record the video in an avi format……
and it is easy to execute if you know how to configure JMF etc………..
please leave a comment personally to this mail – id nagakiran5@in.com, if it got really helpful to you, and if you have any douts how to run this……..
I tried this code,but when it capture image it show only black screen…..
plz help me to slove this….
Are you sure about the functionality of Webcam through this program? If so, sorry, I’ve no idea about the reason for that.
can you post me which code have you tried so that we can find the problem and solve it………..
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Frame;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Vector;
import javax.imageio.ImageIO;
import javax.media.*;
import javax.media.control.FrameGrabbingControl;
import javax.media.format.RGBFormat;
import javax.media.format.VideoFormat;
import javax.media.util.BufferToImage;
/**
*
* @author BUDDHIMA
*/
public class WebCam {
CaptureDeviceInfo device;
MediaLocator ml;
Player player;
Component videoScreen;
public static void main(String args[]) {
new WebCam();// create a new instance of WebCam in main function
}
WebCam() {
try {
//gets a list of devices how support the given videoformat
Vector deviceList = CaptureDeviceManager.getDeviceList(new RGBFormat());
System.out.println(deviceList.toString());
//gets the first device in deviceList
device = (CaptureDeviceInfo) deviceList.firstElement();
ml = device.getLocator();
player = Manager.createRealizedPlayer(ml);
player.start();
videoScreen = player.getVisualComponent();
Frame frm = new Frame();
frm.setBounds(10, 10, 900, 700);//sets the size of the screen
// setting close operation to the frame
frm.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
});
//place player and video screen on the frame
frm.add(videoScreen, BorderLayout.CENTER);
frm.add(player.getControlPanelComponent(), BorderLayout.SOUTH);
//frm.setVisible(true);
frm.setVisible(true);
//capture image
Thread.sleep(5000);//wait 10 seconds before capturing photo
FrameGrabbingControl fgc = (FrameGrabbingControl) player.getControl(“javax.media.control.FrameGrabbingControl”);
Buffer buf = fgc.grabFrame();//grab the current frame on video screen
BufferToImage btoi = new BufferToImage((VideoFormat) buf.getFormat());
Image img = btoi.createImage(buf);
saveImagetoFile(img, “MyPhoto.jpg”);//save the captured image as MyPhoto.jpg
} catch (Exception e) {
System.out.println(e);
}
}
private void saveImagetoFile(Image img, String string) {
try {
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();
String fileType = string.substring(string.indexOf(‘.’) + 1);
ImageIO.write(bi, fileType, new File(string));
} catch (Exception e) {
}
}
}
try this code for capturing image and reply me
i was trying to take a img from camera in java program
it return java.util.NoSuchElementException exception
what I do please help me
Hi Deepak,
This happens because JMF can’t detect your camera. My suggestion is to try an alternative solution.
How we use the “CaptureDeviceManager” to filter the elements as you described at the beginning,can you put that in step by step
it takes some time i have little time , but i will get you back soon with your question with step by step procedure and code….. reply me with which type of module you are working on JMF for example image capturing, video recording etc…..
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Frame;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Vector;
import javax.imageio.ImageIO;
import javax.media.*;
import javax.media.control.FrameGrabbingControl;
import javax.media.format.RGBFormat;
import javax.media.format.VideoFormat;
import javax.media.util.BufferToImage;
/**
*
* @author BUDDHIMA
*/
public class WebCam {
CaptureDeviceInfo device;
MediaLocator ml;
Player player;
Component videoScreen;
public static void main(String args[]) {
new WebCam();// create a new instance of WebCam in main function
}
WebCam() {
try {
//gets a list of devices how support the given videoformat
Vector deviceList = CaptureDeviceManager.getDeviceList(new RGBFormat());
System.out.println(deviceList.toString());
//gets the first device in deviceList
device = (CaptureDeviceInfo) deviceList.firstElement();
ml = device.getLocator();
player = Manager.createRealizedPlayer(ml);
player.start();
videoScreen = player.getVisualComponent();
Frame frm = new Frame();
frm.setBounds(10, 10, 900, 700);//sets the size of the screen
// setting close operation to the frame
frm.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
});
//place player and video screen on the frame
frm.add(videoScreen, BorderLayout.CENTER);
frm.add(player.getControlPanelComponent(), BorderLayout.SOUTH);
//frm.setVisible(true);
frm.setVisible(true);
//capture image
Thread.sleep(5000);//wait 10 seconds before capturing photo
FrameGrabbingControl fgc = (FrameGrabbingControl) player.getControl(“javax.media.control.FrameGrabbingControl”);
Buffer buf = fgc.grabFrame();//grab the current frame on video screen
BufferToImage btoi = new BufferToImage((VideoFormat) buf.getFormat());
Image img = btoi.createImage(buf);
saveImagetoFile(img, “MyPhoto.jpg”);//save the captured image as MyPhoto.jpg
} catch (Exception e) {
System.out.println(e);
}
}
private void saveImagetoFile(Image img, String string) {
try {
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();
String fileType = string.substring(string.indexOf(‘.’) + 1);
ImageIO.write(bi, fileType, new File(string));
} catch (Exception e) {
}
}
}
this peace of code tells you the step by step procedure
and observe the comment lines description you will come to know
hiii friends…….. im new for java technology. i wna code for capture image or record video for all types of media not for particular. any one can help me……
i tried above one. its given same response as given to others like \
[]
null exception
plese help me i need ur help.. plaese
hi friends i am new for java technology. i want code for displaying image or capture the video from webcam using with out jmf. pls help me thanks in advance
Hi,
You can try the alternatives given in previous comments.
Hope those will solve your problem.
Please I need simple code to display my pc camera on Jpanel1 i have it on frame?
Hi halkawt,
It’s simple. You can use Jpanel instead of Frame here. If you want an example, have a look at this:
http://www.sourcepod.com/zmfdet74-8732
Hi buddhima,
thank u for all help to me , but the panel can not display any camera !!!
Hi halkawt,
If you didn’t get any exceptions, give a try again. Because that code actually worked for me 🙂
Thank u my friend , ok this Exception occur when i run the program, “java.util.NoSuchElementException”. remember my package name is application50 is not problem
Hi,
The problem might be with the JMF. Your computer is not supporting it. Please try an alternative solution (some of them are mentioned in previous comments).
Hi Buddhima i have one Q. how i can to display more than one camera in same frame multi Panel?
Hi halkawt,
As you can see there are list of devices in deviceList. but in here I’m using deviceList.firstElement() to get the first.
I think you can display multiple camera’s by accessing to other devices in that list.
thank you
Hi Buddhima, how can to set Dimension of camera in small panel in java
Hi halkawt,
Hope you might find some clue here: http://stackoverflow.com/questions/8503473/setting-the-webcam-resolution-with-java-jmf
First you have to get list of formats that supports and then apply a suitable format to FormatControl of the player.
thanks
java.util.NoSuchElementException
this code doesn,t work my laptop inbuild web cam, is this not support laptop web cam???? help me
Hi Ranjit
Could you check the “deviceList” you get? If your web cam is not included there, you have to go for an alternative solution.
thanks but how to add webcam in devicelist and how to check it your webcem in devicelist icluded or not
plese help me
Hi Ranjit,
You are welcome. You can see all devices in “deviceList” by printing or debugging.
sorry not work
java.util.NoSuchElementException
this code doesn,t work my laptop inbuild web cam, is this not support laptop web cam?
i use windows 7 os how to ADD divicelist in webcam
your code not work generate above exception plese some more solution friends i wait you
help me ?
thanks
Hi Ranjit,
The program should work if your webcam support JMF, and proved by some of above comments too.
But if your web cam does not support this, you have to find an alternative. Some alternatives are already provided in previous comments, so you can try on them.
hi
i am use window 7 operating system by default camera are not included i use some spacial webcam software . do not include in device list
plese how to solve this problem to run over code
Hi,
JMF does not support all the webcams and I don’t think you can manually add webcam to that list, so you need to work on an alternative (some are given in previous comments)
In My application working fine but i can’t take more the 5 or 6 image its goes to heap
memory space error. could anyone please help me . How to avoid heap memory space error.
Hi Kanagaraj,
According to following link this could occur because you have allocated memory for objects and forgot to set null. I think it’s better if you can set null the buffer and image after saving the image to a file.
Link: http://www.coderanch.com/t/537313/Performance/java/Out-memory-error-java-heap
Is There any code for developing the same sort of application Using JSP actually i was designing a Visitors pass facility for my company where i need to remotely give the application using a webpage where they can capture image and made a entry to the database.
If so can you please give me a download link or something
Hi Aditya,
I can’t give the exact answer you want but following links will help you to add a webcam real-time video to your web page.
For JSP:
1. http://osama-oransa.blogspot.com/2012/06/accessing-webcam-within-jsp.html
2. http://stackoverflow.com/questions/9533773/accessing-webcam-in-jsp-pages
Further more,
For PHP:
http://stackoverflow.com/questions/6129241/how-can-i-add-webcam-capabilities-to-my-site
What if i use flash frameworks inside the JSP???
But i am unable to find out the codes for capturing the image and save it to the database (Oracle 11gr2)
Can you please help – I would be very much grateful to you
Thanks In advance
Hi Aditya,
I’m not families with the technologies you mentioned.
But according to the link [1] I gave above, you can implement an application which saves an image.
Then you have to try on how to save an image into the database (using blob or similar type of data). I think saving in to a db would not be difficult.
but here if i use your code in my jsp page then is there any code to capture the image and name it as an sting array
or is it not possible
actually i’m designing a system for visitors card passes in my company
and many a visitors use to visit again and again
so that gate pass can be made the gate pass thing is already been implemented
but photo identification of each person is required
can you please help, i would be very much thankful to you
i got this error The import javax.media cannot be resolved.
what can i do..
Hi Bharath,
Did you add the .jar files (which comes after installing) in JMF to the project correctly? Installing JMF is not enough.
java.util.NoSuchElementException error I also toke but ı have JMstudio and my webcam is working on that ??? System.out.println(deviceList.toString()); and that code return null and java.util.NoSuchElementException
my operating system is Windows 7
Please help,
Regards,
Emin
Hi Emin,
Could you try the answer given in the link below.
Link: http://stackoverflow.com/questions/2570944/unable-to-detect-capture-device-webcam-through-jmf
🙂
Hi Buddhima,
in my laptop i am trying to execute your code capturing image but it shows an error packages are does not exist
explain to me why it happens and i used netbeans latest version to execute this program
Error:
import javax.media.*;
import javax.media.control.FrameGrabbingControl;
import javax.media.format.RGBFormat;
import javax.media.format.VideoFormat;
import javax.media.util.BufferToImage;
for these packages it shows an error
plz help me as soon as possible
Hi Prasad,
It seems like you haven’t added libraries correctly. First you need to install JMF in your computer. Then you need to add library files installed in to your project lib folder. Hope you can find about adding libraries in to lib folder.
Hi Buddhima,
First of all thanks for your wonderful contribution. I am able to do video recording and image capturing and that is working perfectly fine. I just need one help, can we add video setting control like brightness,contrast,hue, sharpness etc. like video control in the player.I don’t want to use VLCJ apart from VLCJ is there any way. If yes please help me. I am in middle of some urgent project and not able to proceed further.
Thanks in advance.
Dhiraj
Hi Dhiraj,
Thanks for appreciations 🙂
I spent sometime on searching for a solution. Finally ended up with the following conclusion.
Adjusting camera settings is related to driver and lower level. (http://www.sitepoint.com/forums/showthread.php?581949-Java-Media-Framework). What you can do is, post processing. Grab image at best quality and then format it (there are tools to do image processing).
But there are alternatives too, For example:http://stackoverflow.com/questions/4723390/controlling-camera-controls-via-gui points to http://www.humatic.de/htools/dsj.htm
Hope the answer will help your project.
Cheers !!!
Gr8 Buddhima, Thx a lot for your help, these are really a helpful link.
Thanks again.
Dhiraj
hi good work every one i have a problem that is when i run this code by eclipse java virtual machine launcher say a java exception has occurred
if anybody could help me please thanks
Hi, Can you put more details about the exception?
Hi, Its nyc work..
I have deployed this on a server and now i want to access the webcam of client when he log in to my server and record a video of him. I am successful with recording a video at server end.
I think may be i need to use a client side technology for this but is there any other way ?
Hi Dave,
I came across the following link while searching: http://www.html5rocks.com/en/tutorials/getusermedia/intro/#toc-gettingstarted
Hope it may help.
Thank You!