Set matOriginal to be the image in imgs folder
[3501/OpenCVShowImage] / IsolateImage.java
CommitLineData
0e9212ae
E
1import java.awt.Graphics;
2import java.awt.Panel;
3import java.awt.image.BufferedImage;
4import java.io.IOException;
5import java.net.URL;
6
7import javax.imageio.ImageIO;
8import javax.swing.JFrame;
9
10import org.opencv.core.Core;
fb24aa85 11import org.opencv.core.Mat;
0e9212ae 12import org.opencv.core.Scalar;
7a245e8b 13import org.opencv.imgcodecs.Imgcodecs;
0e9212ae
E
14
15public class IsolateImage extends Panel {
16 BufferedImage image;
17
fb24aa85 18 public static Mat matOriginal;
7a245e8b 19 public static Mat filtered;
fb24aa85 20
0e9212ae
E
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 {
fb24aa85
E
57
58 matOriginal = new Mat();
7a245e8b 59 filtered = new Mat();
fb24aa85 60
0e9212ae
E
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 }
7a245e8b
E
77
78 public static void processImage() {
79 matOriginal = Imgcodecs.imread("imgs/testpicture.png"); // convert image
80 // into matrix
81
82 }
0e9212ae 83}