Commit | Line | Data |
---|---|---|
0e9212ae E |
1 | import java.awt.Panel; |
2 | import java.awt.image.BufferedImage; | |
0e9212ae E |
3 | |
4 | import org.opencv.core.Core; | |
fb24aa85 | 5 | import org.opencv.core.Mat; |
0e9212ae | 6 | import org.opencv.core.Scalar; |
7a245e8b | 7 | import org.opencv.imgcodecs.Imgcodecs; |
0e9212ae E |
8 | |
9 | public class IsolateImage extends Panel { | |
8f580bc8 E |
10 | BufferedImage filteredImage; |
11 | BufferedImage origImage; | |
0e9212ae | 12 | |
fb24aa85 | 13 | public static Mat matOriginal; |
7a245e8b | 14 | public static Mat filtered; |
fb24aa85 | 15 | |
0e9212ae E |
16 | public static final Scalar LOWER_BOUNDS = new Scalar(103, 164, 169); |
17 | public static final Scalar UPPER_BOUNDS = new Scalar(125, 229, 255); | |
18 | ||
19 | static { | |
20 | System.loadLibrary(Core.NATIVE_LIBRARY_NAME); | |
21 | } | |
22 | ||
23 | public IsolateImage() { | |
0e9212ae | 24 | |
0e9212ae E |
25 | } |
26 | ||
27 | public static void main(String args[]) throws Exception { | |
fb24aa85 E |
28 | |
29 | matOriginal = new Mat(); | |
7a245e8b | 30 | filtered = new Mat(); |
fb24aa85 | 31 | |
8f580bc8 | 32 | processImage(); |
0e9212ae | 33 | } |
7a245e8b E |
34 | |
35 | public static void processImage() { | |
36 | matOriginal = Imgcodecs.imread("imgs/testpicture.png"); // convert image | |
37 | // into matrix | |
38 | ||
8f580bc8 E |
39 | Core.inRange(matOriginal, LOWER_BOUNDS, UPPER_BOUNDS, filtered); |
40 | ||
41 | Imgcodecs.imwrite("output.png", filtered); | |
42 | ||
7a245e8b | 43 | } |
0e9212ae | 44 | } |