Announcing OpenCV for Processing

I’m proud to announce the release of OpenCV for Processing, a computer vision library for Processing based on OpenCV.

You can download it here.

The goal of the library is to make it incredibly easy to get started with computer vision, to make it easy to experiment with the most common computer vision tools, and to make the full power of OpenCV’s API available to more advanced users. OpenCV for Processing is based on the official OpenCV Java bindings. Therefore, in addition to a suite of friendly functions for all the basics, you can also do anything that OpenCV can do.

The library ships with 20+ examples demonstrating its use for everything from face detection:

Screen Shot 2013-04-08 at 1.22.18 PM

(Code here: FaceDetection.pde)

to contour finding:

contours with polygon approximations

(Code here: FindContours.pde)

to background subtraction:

Background Subtraction

(Code here: BackgroundSubtraction.pde)

to depth from stereo:

Screen Shot 2013-04-12 at 2.27.30 AM

(Code here: DepthFromStereo.pde)

and AR marker detection:

Screen Shot 2013-04-12 at 12.20.17 AM

(Code here: MarkerDetection.pde)

So far, OpenCV for Processing has been tested on 64-bit Mac OSX (Lion and Mountain Lion, specifically) as well as 32-bit Windows 7 and 64- and 32-bit Linux (thanks Arturo Castro). Android support hopefully coming soon (pull requests welcome).

It’s already been used in the software for Kinograph, Matt Epler’s DIY film scanner.

OpenCV for Processing was made possible by the generous support of the Processing Foundation and O’Reilly Media. I’ve received invaluable guidance along the way from Dan Shiffman, Andres Colubri, Kyle McDonald, and Golan Levin. A lot of the library’s style was inspired by Kyle McDonald’s excellent ofxCv.

A Book!

While the documentation for OpenCV for Processing may look slim at the moment, I’m working on remedying that in a big way. I’m currently under contract with O’Reilly to write an introduction to computer vision, which will act as comprehensive documentation for OpenCV for Processing as well as a general introduction to the field of computer vision.

I’ve already begun work on the book and I’m really excited about it. It will be available through Atlas, O’Reilly’s new online learning environment. As befits a book about computer vision, it’ll make extensive use of multimedia and interaction. I’m also proud to announce that I’ve worked with O’Reilly to ensure that the book will be Creative Commons licensed from its inception. It will live on Github and accept contributions and corrections from the community. Watch this repo for details.

Why a New OpenCV Library for Processing?

Previously, there have been two OpenCV libraries for Processing, both of them French in origin.

There’s the venerable library by Atelier Hypermedia. This library was based on OpenCV 1.0 and hasn’t been updated in quite awhile. It never made the jump to Processing 2.0.

There’s also JavacvPro, which is based on JavaCV, a widely used Java wrapper for OpenCV. While I’ve used JavacvPro successfully in projects before, it has a number of shortcomings. It requires its user to build OpenCV from source, which is a major stumbling block, especially for the typical Processing user. OpenCV for Processing, on the other hand, bundles OpenCV so it installs like any other Processing library. While JavacvPro uses a relatively recent version of OpenCV, it is written in an older style, using OpenCV classes that require manual memory management. The result is that JavacvPro leaks memory and has some other erratic runtime behaviors. OpenCV for Processing uses the official Java API, which only provides access to modern memory-managed OpenCV structures. Hence, it benefits from the memory correctness and efficiency of the OpenCV developers (who are much smarter than I could ever hope to be) and doesn’t have (known) memory leaks.

Finally, JavacvPro depends on JavaCV, which slows the rate at which it keeps up with changes in the OpenCV API, and also makes it impossible for end-users to benefit from the huge amount of OpenCV documentation and support available online. Users of OpenCV for Processing can simply open the official OpenCV javadocs and start calling functions.

Caveats and Concerns

UPDATE: This section describes a problem that was present when this library was released in July of 2013. As of Processing 2.0.3 (circa Fall 2013) this problem is fixed and OpenCV for Processing should work fine with any subsequent version of Processing.

OpenCV for Processing is currently at version 0.4. It most certainly has bugs and could use serious improvement. Please find these bugs and tell me about them!

The most significant known problem is, thankfully, a temporary one that most affects users on Macs with Retina displays attempting to process video.

In the official release of Processing 2.0, the Capture and Movie libraries don’t provide access to the pixels[] array in the OpenGL-based renderers (P2D and P3D). This is a temporary stop-gap condition that will be fixed in the next release of Processing (hopefully coming in the next few weeks).

On non-retina machines, you can fix the problem by switching to the JAVA2D renderer. However, that renderer doesn’t work on Retina Macs. If you’re on a Retina Mac, you have two options: you can build Processing from source or download the older 2.0b8 version.

Hopefully all of this will be fixed soon due to Andres’s amazingness and we can forget about it.

Enjoy playing with OpenCV for Processing and be sure to show me what you build!

This entry was posted in Art. Bookmark the permalink.

118 Responses to Announcing OpenCV for Processing

  1. Ask says:

    Yeah! Great work, have always been wanting to dive deeper into computer vision, but with no time to venture away from Processing. I’m looking forward to check it out!

  2. adamh says:

    Awesome news and work!
    Wondering if there is any plan to add the blobs() functionality from the ubaa lib ?
    or an alternate method to roll our own with your lib?

  3. greg says:

    The current Contour api is very similar to that: It finds shapes in an image and represents them as a series of points. There’s no actual concept of “blobs” as such in OpenCV itself. I think people usually use that term to refer to code they add on top of the OpenCV contour tools to add things like persistence (heuristics for guessing which contour is which from across sequential frames). I am planning on adding some code like that.

    I have an implementation of Dan Shiffman’s technique for doing continuity with face rectangles, but I want to improve the performance (and clean it up so that it works on both contours and faces) before I put it in the library. Dan’s blog post on the topic is here: already implemented

  4. p0ulp says:

    Very nice work ! it work totally out of the box … incredible for an openCV processing lib :)

    Do you have any advice for integrating this libs in Eclipse, my question focuses on the native lib integration to run the application in the Eclipse IDE and to make export runnable Jar ?

    Sorry for my english, and thank you for the good work

  5. mio says:

    wow looks very nice … gonna run some tests now … im very interested to see how fast it is.

    Anyway do you think that the 3d calib methods allow to calculate homographic transformation like extrinsics and intrinsics between a projector and a kinect?

    • greg says:

      You should look at the RGBD Toolkit project. They do exactly that. I haven’t wrapped most of the related methods (just started with the chessboard detection), but you can call anything that’s available in the OpenCV Java API yourself, so you could definitely do this following the RGBD Toolkit example.

      • mio says:

        thank you looks great…i tried to manage sth. similar with previous cv P5 versions. maybe i find some examples to contribute. Anyway thank you for your tremendous effort and open source approach

        • greg says:

          Thanks! I’d love examples, especially in this area as it’s not something I work with frequently, but it’s an exciting and import part of what OpenCV can do.

  6. So far on Snow Leopard 10.6.8 its not working under processing 2

    Unsatisfied link errors with the java file or class file

    Ill post some error descriptions to further help on github as issues

  7. Great news for all Processing users. I already tried it with OSX two weeks ago, but back then windows wasn’t supported yet (so I had to do work arounds with the native lib as presented by Joshua Noble: But compiling those libraries is not something that fits (or should fit) in the mindset of the average Processing user.

    Do you plan 64bit Windows as well?

    • greg says:

      Windows 32-bit support is working great now. I’d love to do 64-bit support as well but I don’t currently have access to a 64-bit windows system. Pull requests welcome!

  8. greg says:

    @Ashley Brown: Make sure you have Processing set to run in 64-bit rather than 32-bit mode. There’s a setting in the preferences and you’ll have to restart Processing.

    @Kasper Kamperman: I’m not sure if the Windows-build of OpenCV included 32-bit binaries. I’ll double check and if it does I’m happy to support it. If not, I’d need the help of someone who’s more expert at building things on Windows to create those binaries.

    • “I’m not sure if the Windows-build of OpenCV included 32-bit binaries”. You mean 64-bit binaries I suppose? Since 32-bit is supported by your library.
      Both a included in the build version of OpenCV:

      See also the comments I’ve made in the URL (factoryfactory) posted in my 1st commend.

  9. dfamil says:


    i am getting this error with 2.01
    OpenCV for Processing 0.4 by Greg Borenstein
    Using Java OpenCV
    Cascade failed to load

  10. Nic says:

    I’m also getting the “Cascade failed to load” message. I’m using Windows 7 (64bit).
    Any fix yet? Thanks for the great lib otherwise

  11. reid harward says:

    I’m getting the following error: “No library found for gab.opencv” when attempting to run any of the examples on a mac pro running Processing 2.0b8 under os 10.8.4. the folder created after the download unzips is called “opencv-processing-0.4″. Is this the proper name for this library folder? Wonder if this would work better on an older (2 years old) laptop with the latest version of processing?

    • greg says:

      Did you move the library folder into your Processing libraries folder? You can find the location of that folder by looking in the Processing preferences. Once you’re moved the opencv-processing folder into that directory, you’ll also need to restart Processing before it recognizes the library.

  12. p0ulp says:

    Again, great works !

    For information, the macos export with PDE don’t work for LiveCamTest.pde.

    By the way in a previous reply i wrote about Eclipse : i succeed to load the native libs, but didn’t succeed to load the cascade file.

    Any idea to fix this ?

    Thank you

    • p0ulp says:


      For information, i worked on this project, the last weekend and i made some optimisations.

      > I noticed that the 32bit version didn’t work on macos : i refactored the native lib forlder to have a macos64 and a windows32 as inticated in the processing wiki.
      > I noticed that the macos export didn’t work due to the loading of native lib : i made a dynamic loading of this lib for macos64 and windows32 so the export work great now for both os, and the use of your librarie is easier in eclipse. (my code i based on the same system of the video librarie from Andrés Colubri)
      > I noticed that the Cascad loading didn’t work on windows, so i updated the dynamic loading, so now it works great and the use of your librarie is easier in eclipse. (my code i based on the same system of the video librarie from Andrés Colubri)

      Do you want i fork the prject on github with this update ?

      Thank you and sorry for my bad english

      • iain says:

        Am having the same ‘Cascade failed to load’ with windows 7 and Processing 2.0.1 – 32bit. Can you clarify your work around? I am unfamiliar with the appropriate syntax for loading the “haarcascade_frontal_face_alt.xml” directly and would like to try that at least…Thanks.

    • greg says:

      Thanks for the pull request! Integrated! Much appreciated!

  13. Joe says:

    It would be awesome if this would work on Win 64-bit. Looking forward to that update.

  14. William says:

    I have installed it (Windows 7), but when I try to run one face detection example sketch, it can’t find the gab library (“no package found for gab.opencv”). Any clue, please?

  15. Pingback: Imperdibles (julio 10th – julio 15th) » Hipertextos [desde La Plata]

  16. iain says:

    Edit: haarcascade_frontalface_alt.xml

  17. Sid St says:


    The library 0.4 is compatible with which version of the Processing?

    And will be added to library “SURF”?

    I’m having a lot of trouble to develop a detector objects with javacvPro.

    Thank you and congratulations.

    My system:
    Windows Stater 32 bits

    • Sid St says:

      *Windows Vista Starter 32 bits.

    • greg says:

      This library should be compatible with most versions of Processing (besides the few versions around the 2.0 release that have the pixels bug mentioned in this post). It works great with the current version of Processing which is currently 2.0.3 as of this writing.

      I haven’t wrapped any of the SURF (or other feature tracking) functionality yet, but you can use anything available in the full OpenCV java api:

  18. Ryan says:

    I’ve got it running within processing 2.0.1 on Mac OSX 10.7.5
    The first time I run the project it grabs the camera and every time I restart it locks up and can’t find the camera again until I unplug it and replug it back it. Any thoughts? Does that sound like more of a processing issue?

    • greg says:

      Yeah OpenCV for Processing isn’t involved in accessing the camera. Maybe try Processing 2.0.3. A lot of bugs got worked out in those first two sub-point releases.

  19. Robert says:


    I use Processing 2.0.1 32bit on Windows 7.
    Most of the examples work fine. But the FaceDetections states the error “Cascade failed to load”. Anything I can do about it?


  20. Peter says:

    Anyone else with this problem: No library found for gab.opencv ?
    Using the latest os x, processing, opencv.

    • greg says:

      Have you installed the library successfully? Do the OpenCV for Processing examples appear in Examples > Contributed Libraries > OpenCV for Processing? Do the examples there run?

  21. MartinMcNoob says:


    Get ready for a clanger of a noob question. Do I need to install openCV to be able to use this library in Processing? Like, do I need to install this ?
    Apologies for asking a silly question.

    • greg says:

      You don’t need OpenCV installed to use this library. You just need to install OpenCV for Processing successfully in your Processing libraries folder and it will do the rest.

      Not a silly question! One of the important goals of this project was to include the OpenCV binaries within itself so that it would be simple to install and not require you to build OpenCV yourself.

  22. stany de bethune says:


    I’m new to both Processing and opencv…..

    after installing your very promissing opencv library on a windows 7 driven PC, I got this laconic message…

    “UnsatisfiedLinkError: …….library\windows\opencv_java245.dll:Can’t load |A 32-bit.dll on a AMD 64-bit platform ”

    Is there a trivial solution to this situation or will this problem be addressed in a following release?

    Thank you.

    • greg says:

      I don’t have a 64-bit windows build of OpenCV to include in the library as I don’t have a 64-bit windows system to make it on. That would make a great contribution from you or someone else. If else made (or found) the correct binary, I’d be happy to include it in the library. Pull requests welcome!

  23. Ryan says:

    Turns out I had a faulty camera… :-(
    new question
    how does one have a different display resolution from the opencv resolution?
    I’m wanting to scan at 320×240 or 640×480 and display video at 1280×720
    plus have it flipped to be more of a mirror.

    • greg says:

      For that case, I’d recommend capturing the video at its full resolution and displaying it at the resolution. Then, each frame, after you’ve displayed the video, you can resize it before passing it into opencv.loadImage(). You’d create your opencv instance at the smaller size and only process the resized smaller image.

  24. Robert says:

    Really great work so far. I tried javaCVpro. But the amount of memory leaks is way too high. I also like that your library is stand alone and doesn’t require openCV to be installed.

    I really would like to see some high level functions implemented. For starters in computer vision (like me) they lower the complexity a lot. (“blob detection”, Image recognition based on SURF ..).

    Thanks for your work and for sharing the results.

    • greg says:

      Thanks! Yeah, the JavaCvPro guys were in a bit of a hole because while JavaCV is based on OpenCV 2, they still use the old pre-Mat data structures which means they have to do memory management manually. Since I use the official OpenCV Java bindings I get to use Mats which are memory managed meaning I don’t have to worry about leaks much (in fact the old pre-Mat data structures aren’t even available in the Java API).

      As far as those high level functions, I’m working on it. I’ve done some experiments with adding blob persistence (blob detection is already there, it’s just called contours). I’m in the midst of wrapping a bunch of the OpenCV machine learning functionality. After that I’d like to work on the feature trackers and camera calibration stuff. That’s very much in the spirit of this library. Contributions are also welcome :)

  25. Great job! Downloading it right now :-)

  26. shrooqi says:

    great works

    sir when i try face detection example it dos not give error it give this:

    OpenCV for Processing 0.4 by Greg Borenstein
    Using Java OpenCV
    Cascade failed to load

    you say that : There’s a known bug with the paths to the cascade files on Windows that I still need to figure out.

    but I’m not that mechanical engineering :)
    I do not know that you r taking about ???
    can you helpe me solve this problem in easy way as possible??? :)

  27. mohammed says:

    Thanx you sir
    cool job
    i face problem with v 0.4 and it give this error
    Using Java OpenCV
    Cascade failed to load
    then you update the library and it still give error but different
    Cascade loaded: haarcascade_frontalface_alt.xml
    plezzz help
    thix shrooqi

  28. Paco says:

    Great work greg!
    I’ve found a bottleneck with loadImage() that reduces frameRate in Processing when you have to process an image in realtime. That happens here, when you convert the PImage to CV format. Is there any way to make this conversion more efficient?

    * Convert a Processing PImage to an OpenCV Mat.
    * (Inspired by Kyle McDonald’s ofxCv’s toOf())
    * @param img
    * The PImage to convert.
    * @param m
    * The Mat to receive the image data.
    public static void toCv(PImage img, Mat m){
    BufferedImage image = (BufferedImage)img.getNative();
    int[] matPixels = ((DataBufferInt)image.getRaster().getDataBuffer()).getData();

    ByteBuffer bb = ByteBuffer.allocate(matPixels.length * 4);
    IntBuffer ib = bb.asIntBuffer();

    byte[] bvals = bb.array();

    m.put(0,0, bvals);

    Thank you!,
    Juan Pablo

    • greg says:

      Well that “bottleneck” is that the pixel data needs to get moved inside the PImage’s BufferedImage. It’s not a bottleneck so much as the actual work that’s being done. Since Mats are only headers for existing image data (and that image data is already in memory inside the BufferedImage somewhere) it should theoretically be possible to create a Mat in place without copying the pixel data. This is how the process works in C++, for example in Kyle Mcdonald’s ofxCv. However, I don’t know of any way in Java to access the actual memory location of the image data, either to get that location within the BufferedImage or to set it within the Mat. I’m not the world’s most advanced Java programmer though, so my lack of knowledge of such a method is not proof of its non-existence. I’d be glad to hear of a way to accomplish that, but I couldn’t find one in my research and no one else I contacted knew of one.

  29. nylki says:

    Thanks for your effort!

  30. Toke Frello says:

    Hi Greg,

    Great work you’re doing!

    I just started a project in which I would like to detect two markers on an object and calculating the object’s angle from that. However, I am facing problems in learning how to use the OpenCV library. For example: Which arguments does startBackgroundSubtraction() take?

    What would you recommend if I want to learn more about the different functions and objects in the library? I am aware of, but I can’t seem to find information regarding specific functions (also, it’s vast!).

  31. Subhendu says:

    How can I install it in Ubuntu 12.04 32 Bit.

    I already have openCV installed on my system with openCV for python by building it from source.

  32. How can I install it in Ubuntu 12.04 LTS

    I already have OpenCV with python support installed by building from source.

  33. Saurabh Datta says:

    I’m trying the “depth from stereo” example and was egar to try it out with realtime video. SO I plugged in one extra webcam and placed it at a side of the Integrated cam at 2.5 cms(for stereoscopy) and first figured out a way to pull in two videos from two webcams at the same time in processing. Then I wrote this code and it’s not working(expected to some extent).
    Help is required as I’m not a coder, just a mere tinkerer:


    import gab.opencv.*;
    import org.opencv.core.Mat;
    import org.opencv.calib3d.StereoBM;
    import org.opencv.core.CvType;
    import org.opencv.calib3d.StereoSGBM;

    OpenCV ocvL, ocvR;
    Capture cam1, cam2, depth1, depth2;

    void setup() {
    size(640, 480);

    String[] cameras = Capture.list();

    if (cameras.length == 0)
    println("There are no cameras available for capture.");
    println("Available cameras:");
    for (int i = 0; i < cameras.length; i++)

    cam2 = new Capture(this, 320, 240, "Integrated Webcam");

    cam1 = new Capture(this, 320, 240, "USB Camera");

    ocvL = new OpenCV(this, cam1);
    ocvR = new OpenCV(this, cam2);


    void draw()

    Mat left = ocvL.getGray();
    Mat right = ocvR.getGray();
    Mat disparity = OpenCV.imitate(left);
    StereoSGBM stereo = new StereoSGBM(0, 32, 3, 128, 256, 20, 16, 1, 100, 20, true);
    stereo.compute(left, right, disparity );
    Mat depthMat = OpenCV.imitate(left);
    disparity.convertTo(depthMat, depthMat.type());
    depth1 = new Capture(this, depthMat.width(), depthMat.height());
    ocvL.toPImage(depthMat, depth1);

    StereoBM stereo2 = new StereoBM();
    stereo2.compute(left, right, disparity );
    disparity.convertTo(depthMat, depthMat.type());

    depth2 = new Capture(this, depthMat.width(), depthMat.height());
    ocvL.toPImage(depthMat, depth2);

    if (cam1.available() == true)
    //set(0, 0, cam1);
    image(cam1, 0, 0);

    if (cam2.available() == true)
    set(320, 0, cam2);

    image(depth1, 0, 240);
    image(depth2, 320, 240);

    fill(255, 0, 0);
    text("left", 10, 20);
    text("right", 10 + 320, 20);
    text("stereo SGBM", 10, 240 + 20);
    text("stereo BM", 10 + 320, 240+ 20);


    • Saurabh Datta says:

      If anybody could explain me this portion in simple language:

      Mat left = ocvL.getGray();
      Mat right = ocvR.getGray();
      Mat disparity = OpenCV.imitate(left);
      StereoSGBM stereo = new StereoSGBM(0, 32, 3, 128, 256, 20, 16, 1, 100, 20, true);
      stereo.compute(left, right, disparity );
      Mat depthMat = OpenCV.imitate(left);
      disparity.convertTo(depthMat, depthMat.type());
      depth1 = new Capture(this, depthMat.width(), depthMat.height());
      ocvL.toPImage(depthMat, depth1);

      StereoBM stereo2 = new StereoBM();
      stereo2.compute(left, right, disparity );
      disparity.convertTo(depthMat, depthMat.type());

      depth2 = new Capture(this, depthMat.width(), depthMat.height());
      ocvL.toPImage(depthMat, depth2);

      • greg says:

        This is an advanced example that mainly uses unwrapped OpenCV functions. You should read the documentation of the relevant functions:

        Mat is the OpenCV type for representing image data. I’m accessing the mats for each of the two images: left and right. Then I create a “disparity map” which is an image that contains data about how the left and right images differed so as to calculate depth data. Then I configure two different OpenCV objects for calculating that depth data, StereoSGBM and StereoBM. Each of these implements a different algorithm for calculating the disparity map with a different approach and a different trade-off between quality and performance. Then, after calculating the disparity map, I load the pixel data back into a PImage to display it in Processing. The other functions there are about setting up the right size and types of Mats for the image data and converting between the various types.

  34. Aleks says:

    “No library found for gab.opencv”, no difference how I try to link it.

    • Aleks says:

      Tried both MacOS and Win32.

    • greg says:

      Did you install the library in your Processing libraries folder and restart Processing? Are you seeing the built-in examples when you look in Processing’s Examples > Contributed Libraries section?

      • Aleks says:

        Installed opencv_processing.jar in proper path,

        Yes I see it in the lib list.

        If I add it to the project, it imports it like this:
        import org.opencv.core.*;
        import org.opencv.calib3d.*;
        import org.opencv.contrib.*;
        import org.opencv.objdetect.*;
        import org.opencv.imgproc.*;
        import org.opencv.utils.*;
        import org.opencv.features2d.*;
        import org.opencv.highgui.*;

        and it gets compiles.

        Yet the examples don’t work with “No library found for gab.opencv”.

        By the way, all the installation instructions it is possible to find in both readmes and the website are
        “### Installing
        OpenCV for Processing is in the early stages of development. Currently it only supports Mac OSX and 32-bit Windows. Linux (and hopefully Android) support coming soon.
        See [here]( for the latest release.”

        I found older github commit where were more info, and tried everything from there as well, but no luck.

        Sorry for the wall of text /=

        • I’m now having the same problem, having finally figured out how to rename the library and .jar files so that Processing can find them. Mac OS 10.9, Processing 2.1.

          • greg says:

            You don’t need to rename anything in order to install the library. Just download the archive linked from the releases page, unzip it, move the folder into your Processing libraries folder (you can get the path for this by looking in Processing’s Preferences menu). Restart Processing and it should show up. If you’re renaming files or moving just jars around, you’ve gone off the rails somehow.

        • greg says:

          @Aleks: It sounds like maybe you’re working in Eclipse rather than the Processing IDE. Is that correct?

  35. MakerBlock says:

    Hi Greg!
    Awesome work! It looks like OpenCV for Processing is optimized for 64-bit Mac OS X with Mountain Lion and Lion and 32-bit Windows 7. Do you have any suggestions on how to get it to work on 64-bit Win 7?



  36. tusshar says:

    will this support android mode ?

  37. tusshar says:

    is a topic on OCR possible…in your upcoming book ?

  38. tusshar says:

    cannot validate shader program : unknown error

    Windows 7 – contour example

    • greg says:

      That’s a weird error as OpenCV for Processing doesn’t use any shaders. What version of Processing are you running and what other code are yo using?

  39. davidv says:

    Hi, thanks a lot for this library, finally wrapper for the new versions of openCv. I have one question though, I want to use it for motion detection so I am using the background subtraction. However, the result picture from your library has the past motion (white color) dissapearing very slowly (in opencv for openframeworks, the output image had only the most recent motion in it) . Any fix for this? Thanks for help.

  40. Pierce says:

    Hi, is there any way to export sketches using opencv as applications? So far I’ve had no luck.

    • greg says:

      Hi, Pierce. I’ve never tried exporting sketches with the library. I don’t really ever export sketches in general. Can you tell me more about what errors you’re seeing?

      • Pierce says:

        Hi Greg. I debugged the .app in terminal and got this:
        “OpenCV for Processing 0.4 by Greg Borenstein
        Using Java OpenCV
        Cascade failed to load”
        I’m modding the LiveCamTest example. The webcam video is drawn, but the face detection never gets called. I thought it was just something I did wrong, but the clean FaceDetection example also doesn’t draw the green box when I export the sketch.

      • Pierce says:

        Just an update in case this ends up being helpful:
        The fact that terminal only said that the cascade file failed to load makes me think that the opencv library is being imported fine, and that the problem lies in how the cascade file is linked. I tried replacing “OpenCV.CASCADE_FRONTALFACE” with “../data/haarcascade_frontalface_alt.xml”. I also tried using Contents/Resources/Java/data/haarcascade_frontalface_alt.xml. No luck yet, but I’ll keep trying.

        • greg says:

          What platform are you on and what version of the library are you using? Before 0.4.1 there was a bug in the file path-generation on Windows that prevented cascade files from loading. That bug has been fixed for the last two releases. If you’re on Windows, try the most recent release and see if that fixes the problem.

          • Pierce says:

            It works! Found out it was multiple problems entirely on my end. Turns out I had several versions of the library installed and it was defaulting to the older one. I got it export fine in Processing 2.0.3. Version 2.1 is still a mystery, but i like 2.0.3 better anyway. Thanks so much Greg!

  41. Absolutely no problems running Processing 2.1 (x86) Windows8 (64bit) with your OpenCV library. Great work!

  42. Having the same problem as many above with gab.opencv. Using Mac OS 10.9 and Processing 2.1. The funny thing is that I can’t even get Processing to see the opencv-processing-master folder in the library folder at all, even after restarting.

    • greg says:

      It sounds like you’re downloading a zip of the entire git repository rather than the actual released library. Go to this page: click the green download button on the topmost release (at the moment that one reads “”). Unzip that archive. Move the folder into your Processing libraries folder (which will be inside your sketchbook location which you can find out by looking in Processing’s Preferences). Restart Processing and then the OpenCV for Processing examples should start showing up under File > Examples > Contributed Libraries. Try running one of those.

  43. Pingback: Week 4 | Creative Coding Intro

  44. Justin Berken says:

    I am attempting to combine the examples with live camera feed and seem to be doing something wrong, I just get blank screen. Could you glance at my code? Thanks!

    import gab.opencv.*;
    import java.awt.*;

    Capture video;
    OpenCV opencv;

    void setup() {
    size(640, 480);
    video = new Capture(this, 640, 480);
    opencv = new OpenCV(this, 640, 480);

    opencv.startBackgroundSubtraction(5, 3, 0.5);


    void draw() {

    image(video, 0, 0);



    stroke(255, 0, 0);
    for (Contour contour : opencv.findContours()) {

    void captureEvent(Capture c) {;

  45. Hello! Thanks for making a new OpenCV for Processing. Do you know of any good resources or tuts for opening video files using OpenCV? I find Processing video libraries restrictive (at least the 64bit mac). I need to read MPEG2 at 1920×1080 resolution. Any help would be greatly appreciated. Cheers :-)

  46. drloop says:

    “No library found for gab.opencv”

    if you get this error-message, try to install the libs by help of the library manager:
    Sketch -> Import Library -> Add Library… -> in the text field type opencv -> press button ‘Install’ next to ‘OpenCV for Processing ‘
    restart processing

    that did the trick for me
    Win7 x64 processing 2.03

  47. Pillsbury says:

    Hi, great development!,
    Is it possible to have a markerless AR on colourful images with this library?

  48. Harold Jarvie says:

    Hiya and Thanks! At the top of this page the “Download it here” link points to the .4 release not the latest release….. maybe why there are so many cascade file loading errors reported.

  49. roberto_pugliese says:

    I get this error (Win8 Processing 2.1)

    A library used by this sketch is not installed properly.
    Cannot load local version of opencv_java245 : Linux 32/64, Windows 32 bits or Mac Os 64 bits are only avaible
    A library relies on native code that’s not available.
    Or only works properly when the sketch is run as a 32-bit application.

    any ideas?


  50. SD says:

    I am helping my son with a project using Kinect + Processing 2.0 and the OpenCV for Processing library. I am using windows platform and the 32 bit environment for processing, kinect and opencv. We found an example on the web for blobs which has the following statement: import*; When we run this Using OpenCV for processing the program crashes. When I search for hypermedia in the subdirectories in OpenCV for processing I can’t find it. What is needed in the install to do this? I also downloaded just openCV and there I can find the hypermedia in the src directory. I am a novice at this stuff. Any help appreciated.

    • greg says:

      Hypermedia is the old OpenCV library for Processing, not this new one that I wrote. It doesn’t work in Processing 2.0. If you’ve installed OpenCV for Processing (the library described here) its examples should show up in Processing’s examples directory (under Contributed Libraries). You should be able to start using it from there by following the examples. The import statement will be: import gab.opencv.*;

  51. Francesco says:

    Hi everybody, I have a Kinect for Xbox 360 and I have to realize a software for an exam in my university. With the software I should recognize the shape of buttons in a washing machine with coordinates and distances from kinect sensor because in future a robot arm will push that buttons. I’m thinking to use my Kinect with OpenCV for Processing to detect and track shapes of object using contours.

    Is it possible?How can do that?
    In the library examples I have found an example with webcam but nothing with other types of camera.

    Thank you very much and very compliments for your effort!

  52. Hello:
    My interest is to build Robot Platforms. You can see what I do on my blog.
    I just started to work with Processing to evaluate if this tool allows me to create Win & Android Programs. Then I found openCV and your site.
    My vision is to use an Android device as a “sensor collector” or as the brain of my units. And for that I need your help: I’m looking for a openCV module that allows odometry. The idea is to use one of the Android photo camaras as a flow camara to measure 2D movement (x,y, Turn). Then, based on that information, and using the incorporated compass, use the android device to track movement.
    Do you have any example / link / hint on how to do this? Would you evaluate to incorporate this feature in your next book?
    Kind Regards
    J. Sanchez

    • greg says:

      Optical flow is supported in OpenCV including in the Java bindings. It’s part of the Video class. You can read the documentation here: All of those functions will work fine with OpenCV for Processing. I haven’t worked much with optical flow, but it is something that I’d like to support in OpenCV for Processing, both in the wrapper and as an example. I probably won’t have time to work on that until this coming summer, but I’d be more than happy to accept a contribution with a basic sketch if you wanted to try it out. I’d even be glad to help debug and get something working if you started to work and got stuck.

  53. Ryan says:

    sir when i tried to use sample code just for face detection i code in processing but theres a problem. could you help me? (No library found for gab.opencv)
    (Libraries must be installed in a folder name ‘libraries’ inside the ‘skectchbook’ folder.)

    How can i fix this?. :(

  54. Furkan Öztürk says:

    Hey, thank you for bringing awesome content to the internet.
    I am trying to find a way to estimate pitch and yaw of the FRONTAL_FACE while I am running a processing sketch much similar to LiveCamTest example.
    Thank you for any of your help

    • greg says:

      Thanks! Viola-Jones object detection only works in 2D so you’re not going to get any of the information you need for face orientation from OpenCV detect() function directly. That said, you could do your own analysis for the face pixels to see if you can figure some of this out yourself. Some simple heuristics around looking for light and dark areas (eye tend to be darker in most lighting conditions because of shadows cast by the brows, etc) or straight lines (try hough detection with the opencv.findLines() function). You could also do a google search to see how computer vision researchers approach the problem of face orientation to see if there’s something simple you can implement yourself. Or, you could use Kyle McDonald’s ofxFaceTracker. That’s an OpenFrameworks project, but he’s built an application that publishes the data about the tracked faces including orientation. There are downloads here:

  55. brainwashed says:

    Hello Greg! Congratulations for your work.
    Could you please help me? I´m using Processing 2.1.1 and I want to import your OpenCV library. I can´t import it from the Library Manager. This is what I get:

    “ at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance( at sun.reflect.DelegatingConstructorAccessorImpl.newInstance( at java.lang.reflect.Constructor.newInstance( at$ at$ at Method) at at at at at$ at Caused by: at at at at at at at … 2 more”

    • brainwashed says:

      Maybe I annoyed you copying all the return message from Processing. Sorry and please feel free to delete may last comment…

      • greg says:

        Not annoyed at all. I just can’t respond to all the comments every day. Have you tried installing it from the Library Manager again since then? I had pushed a bad release around then (accidentally forgot to upload the actual library file!), but I’m pretty sure it’s fixed now and has been for awhile. Sorry you caught the library at a bad moment.

  56. scm6079 says:

    I’ve been playing with the library — nice work. Of course, once you get into much real at all you need to go beyond the library. It would be *VERY* useful if this library provided a few methods similar to the OpenCV Android Utils.* methods.

    Here’s what I’m thinking:
    pImageToMat( PImage imagePimg, Mat mat )

    This would work similar to Utils.bitmapToMat and matToBitmap, providing easy conversion between mats and pimages. You have much of this code right now (e.g. toPImage), but it’s unidirectional and the other method operates on private members and is not accessible. Simply refactoring that to be accessible would be a huge time save for new users.

    Overall this is great work – and I’m sure lots of people (myself included) are going to get a leg up from this.

  57. Danh says:

    Hi Greg,
    I’m not able to get the library to work on 32 bit or 64bit Linux. For example, when using 32bit Xubuntu and 32bit Processing 2.1.1 along with the latest library, running the face detect example results in this error:

    “A library relies on native code that’s not available. Or only works properly when the sketch is run as a 64-bit application.”

    Can you test with a 32 bit version of Ubuntu and tell me if it works on your end?

    Thanks and I look forward to your new book!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>