JAVA image processing based on OpenCv and JVM ----- basic knowledge of matrix objects

The Mat (matrix) object is the core of the OpenCV framework, and you can use OpenCV more easily by mastering it.

working principle

To create a simple matrix with only one channel per "point", one of the following three static functions in the Mat class is usually used: zeros, eye, ones. You can see the purpose of these three functions in the table below.

        

Implement static functions by example

        

import org.opencv.core.CvType;
import org.opencv.core.Mat;
import origami.Origami;
import org.opencv.core.Core;
import static java.lang.System.loadLibrary;


public class HelloCv {
    public static void main(String[] args) throws Exception {
         Origami.init();
         Mat hello = Mat.eye(3, 3, CvType.CV_8UC1);
         System.out.println("mat = ");
         System.out.println(hello.dump());
         Mat mat2 = Mat.zeros(3, 3, CvType.CV_8UC1);
         System.out.println("mat2 = ");
         System.out.println(mat2.dump());
         Mat mat3 = Mat.ones(3, 3, CvType.CV_8UC1);
         System.out.println("mat3 = ");
         System.out.println(mat3.dump());
         Mat mat4 = Mat.zeros(3, 3, CvType.CV_8UC3);
         System.out.println("mat4 = ");
         System.out.println(mat4.dump());
    }
}

 In many cases, you may not create the matrix from scratch, but load the image from a file.

Guess you like

Origin blog.csdn.net/JavaLLU/article/details/122332420