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); println(Core.VERSION); System.loadLibrary(Core.NATIVE_LIBRARY_NAME); noLoop(); } void draw() { background(0); Mat m = Mat.eye(3, 3, CvType.CV_8UC1); println(m.dump()); } |
The command
System.loadLibrary(Core.NATIVE_LIBRARY_NAME); |
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]