OpenCV and Processing 2

The second example loads the OpenCV library; creates an identity matrix; and print its content in the console window.

Example 2

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.CvType;
void setup() {
  size(640, 480);
void draw() {
  Mat m = Mat.eye(3, 3, CvType.CV_8UC1);

The command


will load the opencv-300.jar library in the code folder.

Mat is the major data structure to maintain the matrix data in OpenCV. The static function

Mat.eye(3, 3, CvType.CV_8UC1)

will create an identity matrix of size 3 x 3. Each data item is 1 element of 8 bit unsigned character. For image data we test later, we may use data type CV_8UC3 for the red, green and blue channels.
The last command will print the matrix dump as string. The console output will be

[  1,   0,   0;
   0,   1,   0;
   0,   0,   1]