-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSaveImage.java
55 lines (31 loc) · 1.38 KB
/
SaveImage.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// ********************************************************
// Example : saving an image from file
// Author : Toby Breckon, [email protected]
// Copyright (c) 2015 Durham University
// License : LGPL - http://www.gnu.org/licenses/lgpl.html
// ********************************************************
// import required OpenCV components
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfInt;
import org.opencv.imgproc.Imgproc;
import org.opencv.highgui.Highgui;
// ********************************************************
public class SaveImage {
public static void main(String[] args) {
// load the Core OpenCV library by name
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
// load an image from file (read and decode JPEG file)
Mat inputImg = Highgui.imread("files/lena.jpg");
// create an output object
Mat outputImg = new Mat();
// invert the image
Core.bitwise_not(inputImg, outputImg);
// write image to file (first setting up the compression quality to use)
MatOfInt params = new MatOfInt();
params.fromArray(new int []{Highgui.CV_IMWRITE_JPEG_QUALITY, 75, 0 });
System.out.println( "Saving image to file ...." );
Highgui.imwrite("files/lena_inverted.jpg", outputImg, params);
}
}
// ********************************************************