blob: b0cf9b060158520d5c9cf9532fd348c3a9068ca3 [file] [log] [blame]
danielp4a35a7a2013-02-20 20:45:39 +00001/**
2 *
3 */
4package org.frc971;
5
6/**
7 * @author daniel
8 *
9 */
10
11//get debug images for Java camera processor
12
danielp54e997e2013-02-21 01:54:23 +000013import java.io.File;
14import java.io.IOException;
15
16import java.util.logging.Logger;
17
danielp4a35a7a2013-02-20 20:45:39 +000018import javax.imageio.ImageIO;
19
20import edu.wpi.first.wpijavacv.WPIColorImage;
21
danielp4a35a7a2013-02-20 20:45:39 +000022public class TestImageGetter {
danielp54e997e2013-02-21 01:54:23 +000023
danielp4a35a7a2013-02-20 20:45:39 +000024 private String path_to_images;
danielp54e997e2013-02-21 01:54:23 +000025
26 private final static Logger LOG = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
27
danielp4a35a7a2013-02-20 20:45:39 +000028 final static String[] images = {"45in_DoubleGreen.jpg",
29 "57inLargeTarget_DoubleGreenBK.jpg",
30 "FullField_DoubleGreenBK3.jpg",
31 "FullField_SmallGreen.jpg",
32 "HybridLine_DoubleGreenBK2.jpg",
33 "HybridLine_DoubleGreenBK3.jpg",
34 "HybridLine_DoubleGreenBK4.jpg",
35 "HybridLine_SmallGreen2.jpg",
36 "HybridLine_SmallGreen3.jpg",
37 "HybridLine_SmallGreen4.jpg",
38 "Midfield_DoubleGreenBK2.jpg",
39 "Midfield_SmallGreen2.jpg",
40 "Midfield_SmallGreen3.jpg",
41 "Midfield_SmallGreen4.jpg",
42 "OppLine_DoubleGreenBK2.jpg",
43 "OppLine_SmallGreen2.jpg",
44 "PyramidRight_DoubleGreenBK2.jpg",
45 "PyramidRight_SmallGreen2.jpg"
46 };
47
48 private int image_index = -1;
49
50 private WPIColorImage current_image = null;
51
52 private String cocatenate_paths(String path1, String path2) {
53 if (path1.charAt(path1.length() - 1) == '/')
54 return path1 + path2;
55 else
56 return path1 + "/" + path2;
57 }
58 public TestImageGetter(String path_to_images) {
59 this.path_to_images = path_to_images;
60 }
61 public WPIColorImage GetNext() {
62 image_index++;
63 if (image_index < images.length) {
64 String image_to_get = images[image_index];
65 try {
66 current_image = new WPIColorImage(ImageIO.read(new File(cocatenate_paths(path_to_images, image_to_get))));
67 return current_image;
68 }
69 catch (IOException e) {
danielp54e997e2013-02-21 01:54:23 +000070 LOG.warning("Could not open file.");
danielp4a35a7a2013-02-20 20:45:39 +000071 return null;
72 }
73 }
74 else
75 image_index--;
76 return null;
77 }
78 public WPIColorImage GetPrev() {
79 image_index--;
80 if (image_index >= 0) {
81 String image_to_get = images[image_index];
82 try {
83 current_image = new WPIColorImage(ImageIO.read(new File(cocatenate_paths(path_to_images, image_to_get))));
84 return current_image;
85 }
86 catch (IOException e) {
danielp54e997e2013-02-21 01:54:23 +000087 LOG.warning("Could not open file.");
danielp4a35a7a2013-02-20 20:45:39 +000088 return null;
89 }
90 }
91 else
92 image_index++;
93 return null;
94 }
95 public WPIColorImage GetCurrent() {
96 return current_image;
97 }
98}