As the regular readers of tricksmode know that I am pursuing engineering in Information Technology and a part time blogger. Some day ago, I had to finish a project in java which involves input from webcam or you can say that we have to capture images from webcam. The task was little bit complicated because me and mine team partners don’t know anything about hardware interaction in java. But with the help of some open source java libraries we finished up our task without facing much problems.
The main problem which we faced during implementing libraries is that, The libraries didn’t came with proper getting started documentation, We also searched google on the same but didn’t got any positive response.
So today we are sharing a java swings program to capture webcam images and some essential libraries to implement that program on your machine.
1) Java installed on your computer.
2) An usb camera or webcam.
3) Net beans installed on your computer.
4) LTI-CIVIL java library.
What is an LTI-CIVIL library?
LTI-CIVIL is an open source java library for capturing images from webcam or usb camera. The best thing about this library is that, it doesn’t depend on JMF (Java Media Framework) and works well on windows, Linux and Mac os.
How to configure/implement LTI-CIVIL library to use it with my project?
If you are using net beans then LTI-CIVIL library are very easy to configurable. We just have to set some jar files and dll files and we are done. Just a minute we are showing it step by step.
Here we start,
How To Capture Webcam Images In Java Swings With LTI-CIVIL Library
1) Install java and net beans if you haven’t installed them yet.
2) Open net beans and create a new java project.
3) Now right click on your newly created project and create a new java class and name that “TestWebCam” without quotes.
4) Now copy and paste the following code in TestWebCam.java class.
/*Start copying from here*/
/*Code Ends here*/
5) you will see a lot of errors are coming in code, don’t worry, this is because we didn’t configured LTI-CIVIL libraries yet. To Configure LTI-CIVIL libraries first of all go to this link and download the LTI-CIVIL libraries.
6) Unzip the downloaded folder to desktop.
7) Open the downloaded folder you will see a folder named “native”
Open “Native” Folder and Select your operating system. If you are developing a java swings webcam capture program for windows then open win32 folder. If you are using linux then, Open Linux-amd64 or X86 based on your machine configuration. And mac users open macosx universal folder.
8) Now copy all the contents of the selected folder and paste them your netbeans project folder. For windows users netbeans project folder exists at Documents > NetbeansProjects>Project Name
For windows users, If your project name is “JavaApplication1”, Then go to documents>NetbeansProjects>JavaApplication1 and Paste the copied contents there.
9) Now open Netbeans and right click on your project, Then Go to properties and then select “libraries” from the right panel. Now click on “Compile” tab and then finally click on Add JAR/FOLDER. After that Browse to the LTI-CIVIL folder which we had downloaded earlier. And add these 4 Jar files lti-civil.jar, lti-civil-no_s_w_t.jar , lti-civil-noswt.jar , lti-civil-noutils.jar to your project.
10) Once you had done, you will see that all errors are gone, and the java swings program is properly capturing images from webcam.
Snapshot of Java Webcam Image Capturing Program using LTI-CIVIL
I tried my best to make this article as simple as I can, if you are facing any problem while implementing LTI-CIVIL or this webcam capture program on your computer, Kindly Comment below and give us a chance to help you.