Instaniate Matrix of the original picture
[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
E
12import org.opencv.core.Scalar;
13
14public class IsolateImage extends Panel {
15 BufferedImage image;
16
fb24aa85
E
17 public static Mat matOriginal;
18
0e9212ae
E
19 public static final Scalar LOWER_BOUNDS = new Scalar(103, 164, 169);
20 public static final Scalar UPPER_BOUNDS = new Scalar(125, 229, 255);
21
22 static {
23 System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
24 }
25
26 public IsolateImage() {
27 try {
28 // image file
29 // name is
30 // testpicture.png
31 URL input = this.getClass().getResource(("imgs/testpicture.png"));
32 // this will read the image to save
33 // into a BufferedImage variable
34 image = ImageIO.read(input);
35 } catch (IOException ie) {
36 // this is to spill
37 // out a message
38 // saying
39 // something
40 // doesn't work
41 System.out.println("Error: " + ie.getMessage());
42 }
43 }
44
45 public void paint(Graphics g) {
46 // This is to actually draw the image out,
47 // necessary.
48
49 // Input of a bufferedimage, x, y, then
50 // an observer in this case null.
51 g.drawImage(image, 0, 0, null);
52 }
53
54 public static void main(String args[]) throws Exception {
fb24aa85
E
55
56 matOriginal = new Mat();
57
0e9212ae
E
58 // Creates a window to
59 // display the image
60 JFrame frame = new JFrame("Display image");
61
62 // Gets the image from ShowImage() method
63 Panel panel = new IsolateImage();
64
65 // Adds the image to the new window
66 // panel
67 frame.getContentPane().add(panel);
68
69 // sets the size of the panel
70 frame.setSize(500, 500);
71 // makes it visible
72 frame.setVisible(true);
73 }
74}