Imgproc.cvtColor(matOriginal, matHSV, Imgproc.COLOR_BGR2HSV);
Core.inRange(matHSV, LOWER_BOUNDS, UPPER_BOUNDS, matThresh);
- // Imgcodecs.imwrite("output.png", matThresh);
+ Imgcodecs.imwrite("output.png", matThresh);
Imgproc.findContours(matThresh, contours, matHeirarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
Point center = new Point(rec.br().x - rec.width / 2 - 15, rec.br().y - rec.height / 2);
Point centerw = new Point(rec.br().x - rec.width / 2 - 15, rec.br().y - rec.height / 2 - 20);
- // Imgproc.putText(matOriginal, "hello" + (int) distance,
- // center,
- // Core.FONT_HERSHEY_PLAIN, 20, BLACK);
- // Imgproc.putText(matOriginal, "hello2" + (int) azimuth,
- // centerw,
- // Core.FONT_HERSHEY_PLAIN, 20, BLACK);
+ Imgproc.putText(matOriginal, "hello" + (int) distance, center, Core.FONT_HERSHEY_PLAIN, 20, BLACK);
+ Imgproc.putText(matOriginal, "hello2" + (int) azimuth, centerw, Core.FONT_HERSHEY_PLAIN, 20, BLACK);
System.out.println(distance + "m, " + azimuth + " degrees " + center.x + ", " + center.y);
}
FrameCount++;
- Imgcodecs.imwrite("output.png", matThresh);
+ // Imgcodecs.imwrite("output.png", matThresh);
}
shouldRun = false;
}
import javax.swing.JFrame;
public class ShowImage extends Panel {
- BufferedImage image;
-
- public ShowImage() {
- try {
- // image file
- // name is
- // test.png
- URL input = this.getClass().getResource(("test.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);
- }
-
- static public 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 ShowImage();
-
- // 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);
- }
+ BufferedImage image;
+
+ public ShowImage() {
+ try {
+ // image file
+ // name is
+ // test.png
+ URL input = this.getClass().getResource(("imgs/test.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);
+ }
+
+ static public 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 ShowImage();
+
+ // 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);
+ }
}