We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
opencv processing library for Java (Read 1569 times)
opencv processing library for Java
Apr 27th, 2010, 8:45am
 
I have installed opencv 2.0 on my windows system. System's "path" is set to bin of opencv. Then I have downloaded processing and opencv processing library opencv_01.

I have copied opencv.dll and opencv.jar in the home directory.

I am trying to run the following program on netbeans.

import java.awt.*;
import java.awt.event.*;
import java.awt.image.MemoryImageSource;
import hypermedia.video.*;



public class BlobDetection extends Frame implements Runnable {
     
     
     // program execution frame rate (millisecond)
     final int FRAME_RATE  = 1000/30;
     // threshold value for removing noises
     final float THRESHOLD = 80f;
     
     
     OpenCV cv = null;      // OpenCV Object
     Thread t  = null;      // the program thread
     
     
     
     // the input video stream image
     Image frame       = null;
     Blob[] blobs = null;
     
     
     /**
      * Setup Frame and Object(s).
      */
     BlobDetection() {
           
           super( "Blob Detection Sample" );
           
           
           // OpenCV setup
           cv = new OpenCV();
           cv.capture( 640, 480 );
           cv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT );
           
           
           // frame setup
           this.setBounds( 100, 100, cv.width, cv.height );
           this.setBackground( Color.BLACK );
           this.setVisible( true );
           this.addKeyListener(
                 new KeyAdapter() {
                       public void keyReleased( KeyEvent e ) {
                             if ( e.getKeyCode()==KeyEvent.VK_ESCAPE ) { // ESC : release OpenCV resources
                                   t = null;
                                   cv.dispose();
                                   System.exit(0);
                             }
                             if ( e.getKeyCode()==KeyEvent.VK_SPACE ) // SPACE : record background
                                   cv.remember();
                       }
                 }
           );
           
           
           // start running program
           t = new Thread( this );
           t.start();
           
     }
     
     
     
     /**
      * Release OpenCV resources.
      */
     public void stop() {
           t = null;
           cv.dispose();
     }
     
     
     /**
      * Draw video frame and each detected faces area.
      */
     public void paint( Graphics g ) {
           if ( frame==null || blobs==null ) return;
           
           // draw image
           //g.drawImage( frame, 0, 0, null );
           
           // draw blobs
           for( Blob b : blobs ) {
           
                 // define blob's contour
                 Polygon shape = new Polygon();
                 for( Point p : b.points ) shape.addPoint( p.x, p.y );
                 
                 // fill blob
                 g.setColor( b.isHole ? Color.RED : Color.BLUE );
                 g.fillPolygon( shape );
           }
     }
     
     /**
      * Execute this sample.
      */
     public void run() {
           while( t!=null && cv!=null ) {
                 try {
                       t.sleep( FRAME_RATE );
                       
                       // grab image from video stream
                       cv.read();
                       //cv.flip( OpenCV.FLIP_HORIZONTAL );
                       
                       // create a new image from cv pixels data
                       MemoryImageSource mis = new MemoryImageSource( cv.width, cv.height, cv.pixels(), 0, cv.width );
                       frame = createImage( mis );
                       
                       // prepare image for detection
                       cv.absDiff();
                       cv.threshold( THRESHOLD );
                       
                       // detect blobs
                       blobs = cv.blobs( 30, cv.width*(cv.height/2), 100, true, OpenCV.MAX_VERTICES*4 );
                       
                       // of course, repaint
                       repaint();
                 }
                 catch( InterruptedException e ) {;}
           }
     }
     
     
     /**
      * Main method.
      * @param String[]      list of arguments's user passed from the console to this program
      */
     public static void main( String[] args ) {
           System.out.println( "\nOpenCV blob detection sample" );
           System.out.println( "PRESS SPACE BAR TO RECORD BACKGROUND IMAGE\n" );
           new BlobDetection();
     }

}

I am getting errors like
Verify that the java.library.path property is correctly set and the '\path\to\OpenCV\bin' exists in your system PATH

Exception in thread "main" java.lang.UnsatisfiedLinkError: hypermedia.video.OpenCV.capture(III)V
       at hypermedia.video.OpenCV.capture(Native Method)
       at hypermedia.video.OpenCV.capture(OpenCV.java:945)
       at testprocessing.BlobDetection.<init>(BlobDetection.java:52)
       at testprocessing.BlobDetection.main(BlobDetection.java:155)

Can any one let me know the problem?
Re: opencv processing library for Java
Reply #1 - Apr 27th, 2010, 10:04am
 
There is already a thread about this problem: http://processing.org/discourse/yabb2/num_1238338691.html
Whatever, I got the same problem, than I downloaded the newest() version 2.1.0 of OpenCV and it worked without any problem!!
Page Index Toggle Pages: 1