blob: a61ed60351fa8ef4729f2dc149b67b61fe3a1296 [file] [log] [blame]
danielp4a35a7a2013-02-20 20:45:39 +00001/**
2 *
3 */
4package org.frc971;
5
6/**
7 * @author daniel
8 *
9 */
10
danielp54e997e2013-02-21 01:54:23 +000011import java.io.File;
12import java.io.IOException;
13
14import java.util.logging.Logger;
15
danielp4a35a7a2013-02-20 20:45:39 +000016import javax.imageio.ImageIO;
17
18import edu.wpi.first.wpijavacv.WPIColorImage;
19
danielp64c4e052013-02-23 07:21:41 +000020/** Get debug images for Java camera processor. */
danielp4a35a7a2013-02-20 20:45:39 +000021public class TestImageGetter {
danielp54e997e2013-02-21 01:54:23 +000022
danielp4a35a7a2013-02-20 20:45:39 +000023 private String path_to_images;
danielp54e997e2013-02-21 01:54:23 +000024
25 private final static Logger LOG = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
26
danielp64c4e052013-02-23 07:21:41 +000027 /** The names of our debugging images, without paths.
28 * The GetNext method should be used to get the first
29 * image, and not GetCurrent. */
danielp4a35a7a2013-02-20 20:45:39 +000030 final static String[] images = {"45in_DoubleGreen.jpg",
31 "57inLargeTarget_DoubleGreenBK.jpg",
32 "FullField_DoubleGreenBK3.jpg",
33 "FullField_SmallGreen.jpg",
34 "HybridLine_DoubleGreenBK2.jpg",
35 "HybridLine_DoubleGreenBK3.jpg",
36 "HybridLine_DoubleGreenBK4.jpg",
37 "HybridLine_SmallGreen2.jpg",
38 "HybridLine_SmallGreen3.jpg",
39 "HybridLine_SmallGreen4.jpg",
40 "Midfield_DoubleGreenBK2.jpg",
41 "Midfield_SmallGreen2.jpg",
42 "Midfield_SmallGreen3.jpg",
43 "Midfield_SmallGreen4.jpg",
44 "OppLine_DoubleGreenBK2.jpg",
45 "OppLine_SmallGreen2.jpg",
46 "PyramidRight_DoubleGreenBK2.jpg",
47 "PyramidRight_SmallGreen2.jpg"
48 };
49
50 private int image_index = -1;
51
52 private WPIColorImage current_image = null;
53
danielp64c4e052013-02-23 07:21:41 +000054 /** Helper method to concatenate paths, similar to Python's os.path.join(). */
danielp4a35a7a2013-02-20 20:45:39 +000055 private String cocatenate_paths(String path1, String path2) {
56 if (path1.charAt(path1.length() - 1) == '/')
57 return path1 + path2;
58 else
59 return path1 + "/" + path2;
60 }
danielp64c4e052013-02-23 07:21:41 +000061
62 /** Constructor
63 *
64 * @param path_to_images is the path to the directory where our images are.
65 */
danielp4a35a7a2013-02-20 20:45:39 +000066 public TestImageGetter(String path_to_images) {
67 this.path_to_images = path_to_images;
68 }
danielp64c4e052013-02-23 07:21:41 +000069
70 /** Gets the next debugging image.
71 *
72 * @return Returns a WPIColorImage.
73 */
danielp4a35a7a2013-02-20 20:45:39 +000074 public WPIColorImage GetNext() {
75 image_index++;
76 if (image_index < images.length) {
77 String image_to_get = images[image_index];
78 try {
79 current_image = new WPIColorImage(ImageIO.read(new File(cocatenate_paths(path_to_images, image_to_get))));
80 return current_image;
81 }
82 catch (IOException e) {
danielp54e997e2013-02-21 01:54:23 +000083 LOG.warning("Could not open file.");
danielp4a35a7a2013-02-20 20:45:39 +000084 return null;
85 }
86 }
87 else
88 image_index--;
89 return null;
90 }
danielp64c4e052013-02-23 07:21:41 +000091
92 /** Gets the previous debugging image.
93 *
94 * @return Returns a WPIColorImage.
95 */
danielp4a35a7a2013-02-20 20:45:39 +000096 public WPIColorImage GetPrev() {
97 image_index--;
98 if (image_index >= 0) {
99 String image_to_get = images[image_index];
100 try {
101 current_image = new WPIColorImage(ImageIO.read(new File(cocatenate_paths(path_to_images, image_to_get))));
102 return current_image;
103 }
104 catch (IOException e) {
danielp54e997e2013-02-21 01:54:23 +0000105 LOG.warning("Could not open file.");
danielp4a35a7a2013-02-20 20:45:39 +0000106 return null;
107 }
108 }
109 else
110 image_index++;
111 return null;
112 }
danielp64c4e052013-02-23 07:21:41 +0000113
114 /** Gets the current debugging image. This is vestigial, it is not longer used.
115 *
116 * @return Returns a WPIColorImage
117 */
danielp4a35a7a2013-02-20 20:45:39 +0000118 public WPIColorImage GetCurrent() {
119 return current_image;
120 }
121}