OpenCV 2 in Processing   41 comments

Xavier Hinault recently released a new computer vision library for Processing, based on JavaCV and OpenCV 2: JavacvPro. This is a great contribution to the community, since it appears that the development of the original OpenCV library for Processing has stalled, without moving beyond OpenCV 1.0 support. JavacvPro is based on the very solid JavaCV wrappers by  Samuel Audet, which provide access to the latest version of OpenCV (2.3.1 at the time of writing this), and in fact also allows to use other computer vision frameworks like OpenKinect, and ARToolKit. I did some testing of JavacvPro (version 0.3) on Windows, Mac and Linux, and the results are very promising as I was able to use the library on the three platforms. Xavier has also included many examples in the library package that show how to use it various features.

 The basic requirement to use JavacvPro is to install OpenCV 2.3.1. The installation process depends on the platform, fortunately there are several online resources to figure this out. What I found is the following:

On Windows and Linux, I used the latest stable version of Processing, 1.5.1. However, on MacOSX the library only works with Java in 64-bit mode, which is supported in the latest alphas of Processing 2.0. I tested it on 2.0.a4, changing the “Launch programs in” option to 64-bit in the Preferences menu:

The homepage of JavacvPro also has several videos (in French) demonstrating different use examples, like this one for finger detection:


Posted November 21, 2011 by ac in Programming

Tagged with , , , ,

41 responses to “OpenCV 2 in Processing

Subscribe to comments with RSS.

  1. Hi Andres… have you by chance tested if OpenCV 2.3.1 is backwards compatible with the OpenCV 1.0, and/or the original OpenCV library (and the various blobDetection libraries, jMyron, etc.) ?? Interested to know this, as I have a few sketches that use these, and it might be extremely difficult ro regress…


    ~ Jesse

  2. Answered my own question… no, the older OpenCV or BlobDetection libraries will not work on 2.0… but will still work on 1.5.1

    • I think that most older computer vision libraries that only depend on general PGraphics functionality without making reference to more specific renderers should work on Processing 2.0

  3. hi Andrés,
    I tested the javaCvPro it’s really promising unlike the openCv for processing from which is stopped in time. I have one question, I didn’t find any way to contact Xavier Hinault he even hasn’t an email on the website nor twitter… have you his contact?

  4. Pingback: The pest of having a 64 bit Linux laptop and OpenCV | In my humble opinion…

  5. Pingback: The pain of having a 64 bit Linux laptop and OpenCV | In my humble opinion…

  6. i would like to thank xavier for all his effort to produce javacvpro
    i just request him not to abandon it like the earlier opencv processing library.

  7. Hi, I tryed to follow your example and installed everything. But Processing still says things like

    Exception in thread “Animation Thread” java.lang.UnsatisfiedLinkError: /private/var/folders/cc/7vz5qp4x1ls4h2xcdsbtm1n80000gp/T/libjniopencv_core6456595444068223362.dylib: Library not loaded: lib/libopencv_core.2.3.dylib Referenced from: /private/var/folders/cc/7vz5qp4x1ls4h2xcdsbtm1n80000gp/T/libjniopencv_core6456595444068223362.dylib Reason: image not found

    But the library is installed with Port correctly.

    I’m using latest beta of Processing, on Lion. Any suggestion?

  8. i use opencv2.3.1 under visual studio 2008. I want to know how I can use JavacvPro so in this case??
    please help me

    • JavacvPro is a Processing (Java-based) library, so you can either use it from the PDE (the Processing environment) or from a full fledged Java IDE such as Eclipse or Netbeans. I don’t think you can use it from Visual Studio.

  9. I also installed OpenCV 2.3 successfully through MacPorts but am having trouble using this library. Which directory should OpenCV2.3 be installed into? Mine is located in /opt/local/lib/

  10. Update: The newest version of JavaCVPro should work. Macports installs into /opt/local instead of /usr/local (brew installs here) and I *think the older versions weren’t looking there.

  11. Ok, I install it from source, and the default location is /usr/local/lib/

  12. Pingback: OpenCV mit Processing Installation auf Ubuntu 12.04 « processing – tutorial

  13. javacvpro on mac mountan lion / processing 2.0a8:
    I installed
    – opencv 2x using brew (correctly linked libs ->/usr/local/lib)
    – processing 2.0a8 (set to 64bit)
    – created a local folder and installed javacv (binaries from
    – added the classpath to it (export CLASSPATH=$CLASSPATH:~/tinkering/java/lib/javacv-bin)
    – installed javacvpro to the local libraries folder of processing.

    When I try to start a sample from the javacvpro package, I receive the following error:
    Exception in thread “Animation Thread” java.lang.UnsatisfiedLinkError: /private/var/folders/dd/h2g1lb2d10b5vmd320lmscgr0000gn/T/libjniopencv_core3440981410919750257.dylib: Library not loaded: /opt/local/lib/libopencv_core.2.3.dylib Referenced from: /private/var/folders/dd/h2g1lb2d10b5vmd320lmscgr0000gn/T/libjniopencv_core3440981410919750257.dylib Reason: image not found

    I don’t understand, why it’s searching in /opt/local/lib and why it seaches 2.3. There are only libopencv_core.dylib and a libopencv_core.2.4.dylib there..

    I am not a java guru and I hope, someone with more skills can help :-).

    • I found the problem… brew installed the wrong version of the lib..
      cd /usr/local
      git checkout 071c3eb Library/Formula/opencv.rb
      brew unlink opencv
      brew install opencv

      brew versions opencv
      displays all the possible versions – I used 2.3.1a

      that’s it :-)!

  14. No such Gstreamer factory v412src. All code runs fine except the video processing ones give this error.
    Using windows 64/processing 1.5.1/openCV 2.4.1

  15. Hi! I’m trying to use opencvpro in a Mountain Lion OSX with OpenCV 2.4.2 installed. As I see, the compiled version of the library searches for libopencv_core.2.3.dylib and not the libopencv_core.2.4.dylib that is the one I got from macports. Is there any workaround for this?

    Thanks, F.

  16. Pingback: Proyecto e instalación de la librería OpenCV 2 para Processing | Laboratori de programació creativa

  17. There seems to be a major memory leak/usage with javacvPro, especially with large resolution captures. I can increase the memory to slow it down, but the sketch will eventually crash. Any ideas on how to fix? Also would love to know how to port to OpenCV 2.4!

  18. hey need urgent help……………
    on site

    linux installation guidelines are missing ….Will u please guide me..x

  19. Hi All,

    i tried to improve the memory management of javacvPro and managed to reduce a lot the memory leaks.

    you can download javacvPro-0.5b from here:

    In the 3 supplied Processing 2.0b examples (simple video capture/display, face detect and blob), there is no memory leaks at all.
    (tested on OSX 10.8.2, openCV 2.4.3 and Processing 2.0b7)

    • Yves, Nice work! Memory consumption starts for me around 350MB and creeps up to 405MB and then hovers there nicely. Performance even seems better- much appreciated!

    • Hello Yves, this is great, thanks so much for your contribution! A couple of months ago I took Xavier Hinault’s original 0.5 package and bundled it with the 64bit binaries of the OpenCV libs (this requires some modifications to the dylib files using install_name_tool), and then I put the modified package here. The advantage of this package is that it doesn’t require additional installs of the OpenCV libraries. It would be nice if the same could be done with our patched version, I will try if I get some time to work on it. Another interesting thing to note in relation to OpenCV and Java is that the developers of OpenCV now officially include/support Java bindings. This might be relevant for the future development of OpenCV libraries for Processing.

      • Andreas, i am not an expert developer such as you. Yes of course, your bundle is really smart and would help a lot!

        Can’t we just replace the javacvPro.jar with my javacvPro.jar?

        Anyway, the only mods i made are in the original src file are clearly marked with ‘// YVES’.
        There is stil something that a java expert may easily solve:
        why do i have to write this imageP(PImage imgOut) method? or in other words, why in the line 337 which creates the PImage, this PImage is not garbage collected ?

  20. Hi Andreas and all,

    i’ve updated my javacvPro-0.5b here:

    In (v0.5), i corrected various opencv memory management errors after studying the exemple code of Samuel Audet, the author of javacv. All my mods are marked with comments ‘// YVES’

    But the main memory leak is indeed a bug in Processing itself, the well known PImage memory leak, see for instance
    (usually solved by calling g.removeCache() )

    Xavier’s original code in javacvPro-0.5 heavily uses the new PImage(), mainly in his method toPImage( ) (see line 337 of my code)

    toPImage is called by all his opencv.image(), opencv.getBuffer*(), opencv.getMemory*(), so the leaks are huge mainly in a Processing draw loop.
    You could can get rid of these leaks by calling in your draw loop:

    Or you can use the new opencv methods i created:
    alternative method opencv.imageP(PImage p), opencv.getBuffer*P(PImage p), opencv.getMemory*P(PImage p) where the parameter is a PImage already allocated by your Processing code. The returned PImage is indeed this PImage parameter where the pixels array has been updated.
    This is of course particularly efficient if you can allocate the PImage just once, globally.

    See the Processing examples.

    To use this version with Andreas bundle ( , just replace the javacvPro.jar with mine.

  21. Pingback: SEN, Processing and Experiments in OpenCV | opensen

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: