Based maven
First, the introduction of opencv
<!-- https://mvnrepository.com/artifact/org.bytedeco.javacpp-presets/opencv --> <dependency> <groupId>org.bytedeco.javacpp-presets</groupId> <artifactId>opencv</artifactId> <version>4.0.1-1.4.4</version> </dependency>
Create a form and a number of buttons used to operate
Create several panel to display and label the picture
First read as grayscale images
The System.loadLibrary (Core.NATIVE_LIBRARY_NAME); org.opencv.core.Mat grayImgMat = imread ( " the src \\ \\ Resource " + jTFimgName.getText (), IMREAD_GRAYSCALE); // read as grayscale Imgcodecs.imwrite ( " src \\ \\ gray.png Resource " , grayImgMat); // save mat object file
And then displayed on the label inside
ImageIcon grayIcon = new ImageIcon("src\\resource\\gray.png"); grayIcon.setImage(grayIcon.getImage().getScaledInstance(320, 240, Image.SCALE_DEFAULT));//大小 可以自由设置 jLabGray.setIcon(grayIcon);