0ee66c3ba9bdc752c9d7f80ac1675d2bc3ffc1ab
[3501/OpenCVShowImage] / IsolateImage.java
1 import java.awt.Graphics;
2 import java.awt.Panel;
3 import java.awt.image.BufferedImage;
4 import java.io.IOException;
5 import java.net.URL;
6
7 import javax.imageio.ImageIO;
8 import javax.swing.JFrame;
9
10 import org.opencv.core.Core;
11 import org.opencv.core.Mat;
12 import org.opencv.core.Scalar;
13 import org.opencv.imgcodecs.Imgcodecs;
14
15 public class IsolateImage extends Panel {
16 BufferedImage image;
17
18 public static Mat matOriginal;
19 public static Mat filtered;
20
21 public static final Scalar LOWER_BOUNDS = new Scalar(103, 164, 169);
22 public static final Scalar UPPER_BOUNDS = new Scalar(125, 229, 255);
23
24 static {
25 System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
26 }
27
28 public IsolateImage() {
29 try {
30 // image file
31 // name is
32 // testpicture.png
33 URL input = this.getClass().getResource(("imgs/testpicture.png"));
34 // this will read the image to save
35 // into a BufferedImage variable
36 image = ImageIO.read(input);
37 } catch (IOException ie) {
38 // this is to spill
39 // out a message
40 // saying
41 // something
42 // doesn't work
43 System.out.println("Error: " + ie.getMessage());
44 }
45 }
46
47 public void paint(Graphics g) {
48 // This is to actually draw the image out,
49 // necessary.
50
51 // Input of a bufferedimage, x, y, then
52 // an observer in this case null.
53 g.drawImage(image, 0, 0, null);
54 }
55
56 public static void main(String args[]) throws Exception {
57
58 matOriginal = new Mat();
59 filtered = new Mat();
60
61 // Creates a window to
62 // display the image
63 JFrame frame = new JFrame("Display image");
64
65 // Gets the image from ShowImage() method
66 Panel panel = new IsolateImage();
67
68 // Adds the image to the new window
69 // panel
70 frame.getContentPane().add(panel);
71
72 // sets the size of the panel
73 frame.setSize(500, 500);
74 // makes it visible
75 frame.setVisible(true);
76 }
77
78 public static void processImage() {
79 matOriginal = Imgcodecs.imread("imgs/testpicture.png"); // convert image
80 // into matrix
81
82 }
83 }