OpenCV 2.4.4 and Processing

The latest OpenCV 2.4.4 supports the desktop version of Java. We can use the OpenCV functions in the Processing environment herunterladen. Before we write a library for it, we can temporarily test it by putting the opencv-244.jar and libopencv_java244.dylib into the code folder of your sketch rocky soundtrack download kostenlos. For Windows, the dll file should go there as well.

And we also need to perform conversion between the PImage and the OpenCV Mat windows store apps lassen sich nicht herunterladen. I do not want to loop through the pixels array to use bitwise operations. In this case, I use the Java BufferedImage and WritableRaster classes with the 8 bits and 4 channels standard format amazon books.

Here are the example codes that perform the GaussianBlur and Canny functions.

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.CvType;
import org.opencv.core.Size;
import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;
import java.awt.image.Raster;
Capture cap;
int pixCnt;
BufferedImage bm;
PImage img;
void setup() {
  size(640, 480);
  cap = new Capture(this, width, height);
  bm = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
  img = createImage(width, height, ARGB);
  pixCnt = width*height*4;
void convert(PImage _i) {
  bm.setRGB(0, 0, _i.width, _i.height, _i.pixels, 0, _i.width);
  Raster rr = bm.getRaster();
  byte [] b1 = new byte[pixCnt];
  rr.getDataElements(0, 0, _i.width, _i.height, b1);
  Mat m1 = new Mat(_i.height, _i.width, CvType.CV_8UC4);
  m1.put(0, 0, b1);
  Mat m2 = new Mat(_i.height, _i.width, CvType.CV_8UC1);
  Imgproc.cvtColor(m1, m2, Imgproc.COLOR_BGRA2GRAY);   
  Imgproc.GaussianBlur(m2, m2, new Size(7, 7), 1.5, 1.5);
  Imgproc.Canny(m2, m2, 0, 30, 3, false);
  Imgproc.cvtColor(m2, m1, Imgproc.COLOR_GRAY2BGRA);
  m1.get(0, 0, b1);
  WritableRaster wr = bm.getRaster();
  wr.setDataElements(0, 0, _i.width, _i.height, b1);
  bm.getRGB(0, 0, _i.width, _i.height, img.pixels, 0, _i.width);
void draw() {
  if (cap.available()) {
    image(img, 0, 0);


7 Replies to “OpenCV 2.4.4 and Processing”

  1. You say “test it by putting the opencv-244.jar and libopencv_java244.dylib into the code folder of your sketch. For Windows, the dll file should go there as well.” I have done this (Windows 7), and restarted Processing, but it can’t find the org.opencv libraries. Can you say excatly where to put these libraries? Thanks.

    1. You have to set the class path of the ‘opencv-244.jar’ in the environment variables.
      Refer this Link.

  2. Hi,
    I try to use your example however the libopencv_java244.dll is not included in the OpenCV build folder. I’ve downloaded from someone over here:

    However then I get an error: Unsatisfied Link Error…. libopencv_java244.dylib not loaded.

    Can you provide the right files, or do I have to build OpenCV myself. Since I’m mainly a Processing user, I don’t really know how to do this (but maybe you have a good resources for me).

Comments are closed.