Monday, 27 May 2013

Video Processing or Image Processing through Webcams / Gesture making API

Video Processing is becoming the source of revolutionary technology as Gestures are being used to manipulate objects in physical world with digital world . As Pranav Mistry gave that presentation on Sixth Sense Device ,there is ongoing research and development on gestural interfaces.

Marvin Framework provides extensible, cross-platform and open source image processing framework developed in Java. The framework provides features to:
  • manipulate images
  • manipulate captured video frames
  • multithreading image processing
  • integrate plug-ins with Graphical User Interface(GUI)
  • analyze plug-in performance
  • extend features via plug-in
  • unit test automation
Marvin Framework  has got varied range of plugins to manipulate frames of image captured from webcam so that gesture can be formed and can be used to make some action based on that.

As we have released Marvin Framework 1.4.3  , a change we have done , now it can work with JavaCV or any other API . If you download jar file through above highlighted link , you need to do the following steps to start working again on Marvin Framework.

STEP 1 -  Download Jar file from above highlighted link , after downloading extract it in some folder, make sure you have already setup JavaCV  .

STEP 2 - Create a project in Eclipse

 STEP 3 - Give the project name as SimpleVideoTest

STEP 4 - Create class SimpleVideoTest in package com.example.test

STEP 4 - Copy paste the code from below .

  1. package com.example.test;
  2. import javax.swing.JFrame;
  3. import marvin.gui.MarvinImagePanel;
  4. import marvin.image.MarvinImage;
  5. import;
  6. import;
  7. public class SimpleVideoTest extends JFrame implements Runnable{
  9.         private MarvinVideoInterface    videoAdapter;
  10.         private MarvinImage                             image;
  11.         private MarvinImagePanel                videoPanel;
  13.         public SimpleVideoTest(){
  14.                 super("Simple Video Test");
  16.                 // Create the VideoAdapter and connect to the camera
  17.                 videoAdapter = new MarvinJavaCVAdapter();
  18.                 videoAdapter.connect(1);
  20.                 // Create VideoPanel
  21.                 videoPanel = new MarvinImagePanel();
  22.                 add(videoPanel);
  24.                 // Start the thread for requesting the video frames
  25.                 new Thread(this).start();
  27.                 setSize(800,600);
  28.                 setVisible(true);
  29.         }
  31.         public static void main(String[] args) {
  32.                 SimpleVideoTest t = new SimpleVideoTest();
  33.                 t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  34.         }
  35.         @Override
  36.         public void run() {
  37.                 while(true){
  38.                         // Request a video frame and set into the VideoPanel
  39.                         image = videoAdapter.getFrame();
  40.                         videoPanel.setImage(image);
  41.                 }
  42.         }
  43. }

Hold on a sec ,many errors i know.

STEP 5 - Add marvin_1.4.3.jar from extracted folder in location " MarvinFramework_1.4.3\marvin\framework "to build path.

STEP 6 - If you have done carefully  , then all the errors have been gone now. Please check the method call videoAdapter.connect(1) , here 1 is referring to capture device '1' so  may be you can get exception

You can try using 0 in place of 1 , or run this code to get the device number of webcam or more than one webcam you may be having to list the device number , you can run the following code

  1. import com.googlecode.javacv.cpp.videoInputLib.videoInput;
  2. class Main {
  5.      public static void main(String[] args) {
  6.            int n=videoInput.listDevices();
  7.            for(int i=0;i<n;i++)
  8.         {
  9.             System.out.println(i+" = "+videoInput.getDeviceName(i));
  11.         }
  13. }
  14. }

In my laptop it outputs like

so this tells that capture device hp webcam has number 0 , so i will change the code to videoAdatpter.connect(0);

You can try different programs available in Sample programs if you download source code of Marvin Project  .

STEP 7 - Run and code !! .

STEP 8 - Have Errors or Exception write to my email anshul dot katta @ gmail

In this tutorial you have seen how to:

  • Setup the Marvin Framework 
  • Create Project in Eclipse using Marvin Project
  • Executing Sample Program to Capture though Webcam

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.