Wednesday, 3 April 2013

Using JavaCV in MarvinFramework

Before you start with  you should first setup the JavaCV in windows. If you haven't , read here.

MarvinFramework is dependent on JMF only in one file,  that is

Gabriel helped me to implement it and hence i have been able to use Marvin Framework with JavaCV.

Pre-requisite : - Marvin Framework Setup 'ed in Eclipse , JavaCV Setup 'ed in Windows wit OpenCV.

1) Create a Project in Eclipse .

Give the project name as JavaCVExample .

Click on Configure Build path as shown in figure

Click on Project tab and click add

Add MarvinFramework and MarvinPlugin workspace into the Project by selecting it.

2) Add javacpp.jar , javacv.jar , jna-3.0.4.jar into build path.

Click on Library tab aside of project tab in Build path window and click on add external lib.

Add javacpp.jar , javacv.jar

Add jna-3.0.4

3) Download these files and then add to the JavaCVExample Project under src , package - test.

Tutorial files 

now paste in test package

4) Now run , your Webcam will start capturing and with plugin EdgeDetector.

5) You can test if JavaCV is setup correctly by running this demo , remember to add img1.png in your project.

We will soon update the Marvin Project with these modifications.

We get lot of advantage in this method, the interface is just need to be implemented by Adapter class , which allows users to choose any video capture API of java , not only JavaCV , but xuggler , FMJ , any API can be used to connect to the camera. Just you need to connect the camera using API and get frames.

Setup JavaCV in Windows

Hello Guys ,

Many of us struggled to get Video capture to work through Java , because of JMF , Oracle shut down the development of JMF after 2009 , it was difficult to capture video from Webcam as with JMF , it always gives Exception : Video Not Found

JavaCV , an OpenCV Java API , is easy to use and working API to do video manipulation with Java language without JMF.

Marvin Framework uses JMF in file MarvinVideoManager.Java 

But i have made it working with JavaCV.

First of all ,let us take a look at

Installation of OpenCV , JavaCV and setting work-space in Eclipse.

1) Download OpenCV from Link1 and JavaCV from Link2.

Also do check the pre-requisite of Open-CV , u need to have Microsoft Visual C++ redistributable package installed and check JDK also , its path and other things.

Microsoft Visual C++ redistributable

For 32 bit: click here
For 64 bit: click here

2) After Downloading Extract the Open CV to this Location :- C:\Opencv\

Please do not extract in other folder because some dll's point to the directory c:\opencv ,so , it can create a problem.

3) Now run this exact command at CMD - SETX /M OPENCV_DIR c:\Opencv\build

This sets the path of OpenCV in Environment .

After that go to Environment Variables in System Properties and set the path accordingly

the path is MyComputer->System Properties->Advanced System Properties.

At Advanced tab click on Environment Variables , there you will find a variable as path , if its not there , click on add make a path variable and enter the value as explained below.

Go to the very last position of the “Path” value and add one of the following strings:

For the 64 bit version, use - ;%OPENCV_DIR%\x64\vc10\bin;
For the 32 bit version, use - ;%OPENCV_DIR%\x86\vc10\bin;

more help here for example setting Environment variable.

look out for semicolon , its important.

4) Next thing is to set up JavaCV , you need to just extract the zip file downloaded , when you make any project in Eclipse using Marvin Framework , add the jars javacpp.jar and javacv.jar into build path.

One more jar is needed , jna-3.0.4 , download from here - LINK

Add all these into Build path of your project.

Try this Tutorial program to Capture through Webcam , Download from here.

After Downloading add these files in Eclipse Project and add all the jars i have already talked about.

See here the next post to use MarvinFramework with JavaCV.

In this tutorial you have seen how to:

  • Install OpenCV
  • Install JavaCV
  • Set up the System Environment Variables
  • Link JavaCV into the project.
  • Link JNA (Java Native Access) into the project.