From 0e9212aef15b22e86dcafecedf778a3d6cc180da Mon Sep 17 00:00:00 2001 From: EvanYap Date: Mon, 17 Oct 2016 19:12:46 -0700 Subject: [PATCH] Create upper and lower bounds variables and setting up the class to display an image --- IsolateImage.java | 68 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 IsolateImage.java diff --git a/IsolateImage.java b/IsolateImage.java new file mode 100644 index 0000000..fc4034f --- /dev/null +++ b/IsolateImage.java @@ -0,0 +1,68 @@ +import java.awt.Graphics; +import java.awt.Panel; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.net.URL; + +import javax.imageio.ImageIO; +import javax.swing.JFrame; + +import org.opencv.core.Core; +import org.opencv.core.Scalar; + +public class IsolateImage extends Panel { + BufferedImage image; + + public static final Scalar LOWER_BOUNDS = new Scalar(103, 164, 169); + public static final Scalar UPPER_BOUNDS = new Scalar(125, 229, 255); + + static { + System.loadLibrary(Core.NATIVE_LIBRARY_NAME); + } + + public IsolateImage() { + try { + // image file + // name is + // testpicture.png + URL input = this.getClass().getResource(("imgs/testpicture.png")); + // this will read the image to save + // into a BufferedImage variable + image = ImageIO.read(input); + } catch (IOException ie) { + // this is to spill + // out a message + // saying + // something + // doesn't work + System.out.println("Error: " + ie.getMessage()); + } + } + + public void paint(Graphics g) { + // This is to actually draw the image out, + // necessary. + + // Input of a bufferedimage, x, y, then + // an observer in this case null. + g.drawImage(image, 0, 0, null); + } + + public static void main(String args[]) throws Exception { + // Creates a window to + // display the image + JFrame frame = new JFrame("Display image"); + + // Gets the image from ShowImage() method + Panel panel = new IsolateImage(); + + // Adds the image to the new window + // panel + frame.getContentPane().add(panel); + + // sets the size of the panel + frame.setSize(500, 500); + // makes it visible + frame.setVisible(true); + } +} -- 2.30.2