fb96b49b2888f8deea618cd4c935cd74ccac1680
[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
14 public class IsolateImage extends Panel {
15 BufferedImage image;
16
17 public static Mat matOriginal;
18
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 {
55
56 matOriginal = new Mat();
57
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 }