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 marvin.video.MarvinJavaCVAdapter;
  6. import marvin.video.MarvinVideoInterface;
  7. public class SimpleVideoTest extends JFrame implements Runnable{
  8.        
  9.         private MarvinVideoInterface    videoAdapter;
  10.         private MarvinImage                             image;
  11.         private MarvinImagePanel                videoPanel;
  12.        
  13.         public SimpleVideoTest(){
  14.                 super("Simple Video Test");
  15.        
  16.                 // Create the VideoAdapter and connect to the camera
  17.                 videoAdapter = new MarvinJavaCVAdapter();
  18.                 videoAdapter.connect(1);
  19.                
  20.                 // Create VideoPanel
  21.                 videoPanel = new MarvinImagePanel();
  22.                 add(videoPanel);
  23.                
  24.                 // Start the thread for requesting the video frames
  25.                 new Thread(this).start();
  26.                
  27.                 setSize(800,600);
  28.                 setVisible(true);
  29.         }
  30.        
  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 {
  3.      
  4.        
  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));
  10.                
  11.         }
  12.        
  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