blob: 1f80520aca4cae266fb70ee8ed049bdd3d9255c6 [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
13import javax.imageio.ImageIO;
14
15import edu.wpi.first.wpijavacv.WPIColorImage;
16
17import java.io.File;
18import java.io.IOException;
19
20public class TestImageGetter {
21 private String path_to_images;
22 final static String[] images = {"45in_DoubleGreen.jpg",
23 "57inLargeTarget_DoubleGreenBK.jpg",
24 "FullField_DoubleGreenBK3.jpg",
25 "FullField_SmallGreen.jpg",
26 "HybridLine_DoubleGreenBK2.jpg",
27 "HybridLine_DoubleGreenBK3.jpg",
28 "HybridLine_DoubleGreenBK4.jpg",
29 "HybridLine_SmallGreen2.jpg",
30 "HybridLine_SmallGreen3.jpg",
31 "HybridLine_SmallGreen4.jpg",
32 "Midfield_DoubleGreenBK2.jpg",
33 "Midfield_SmallGreen2.jpg",
34 "Midfield_SmallGreen3.jpg",
35 "Midfield_SmallGreen4.jpg",
36 "OppLine_DoubleGreenBK2.jpg",
37 "OppLine_SmallGreen2.jpg",
38 "PyramidRight_DoubleGreenBK2.jpg",
39 "PyramidRight_SmallGreen2.jpg"
40 };
41
42 private int image_index = -1;
43
44 private WPIColorImage current_image = null;
45
46 private String cocatenate_paths(String path1, String path2) {
47 if (path1.charAt(path1.length() - 1) == '/')
48 return path1 + path2;
49 else
50 return path1 + "/" + path2;
51 }
52 public TestImageGetter(String path_to_images) {
53 this.path_to_images = path_to_images;
54 }
55 public WPIColorImage GetNext() {
56 image_index++;
57 if (image_index < images.length) {
58 String image_to_get = images[image_index];
59 try {
60 current_image = new WPIColorImage(ImageIO.read(new File(cocatenate_paths(path_to_images, image_to_get))));
61 return current_image;
62 }
63 catch (IOException e) {
64 System.err.println("Could not open file.");
65 return null;
66 }
67 }
68 else
69 image_index--;
70 return null;
71 }
72 public WPIColorImage GetPrev() {
73 image_index--;
74 if (image_index >= 0) {
75 String image_to_get = images[image_index];
76 try {
77 current_image = new WPIColorImage(ImageIO.read(new File(cocatenate_paths(path_to_images, image_to_get))));
78 return current_image;
79 }
80 catch (IOException e) {
81 System.err.println("Could not open file.");
82 return null;
83 }
84 }
85 else
86 image_index++;
87 return null;
88 }
89 public WPIColorImage GetCurrent() {
90 return current_image;
91 }
92}