danielp | 4a35a7a | 2013-02-20 20:45:39 +0000 | [diff] [blame] | 1 | /** |
| 2 | * |
| 3 | */ |
| 4 | package org.frc971; |
| 5 | |
| 6 | /** |
| 7 | * @author daniel |
| 8 | * |
| 9 | */ |
| 10 | |
| 11 | //get debug images for Java camera processor |
| 12 | |
danielp | 54e997e | 2013-02-21 01:54:23 +0000 | [diff] [blame] | 13 | import java.io.File; |
| 14 | import java.io.IOException; |
| 15 | |
| 16 | import java.util.logging.Logger; |
| 17 | |
danielp | 4a35a7a | 2013-02-20 20:45:39 +0000 | [diff] [blame] | 18 | import javax.imageio.ImageIO; |
| 19 | |
| 20 | import edu.wpi.first.wpijavacv.WPIColorImage; |
| 21 | |
danielp | 4a35a7a | 2013-02-20 20:45:39 +0000 | [diff] [blame] | 22 | public class TestImageGetter { |
danielp | 54e997e | 2013-02-21 01:54:23 +0000 | [diff] [blame] | 23 | |
danielp | 4a35a7a | 2013-02-20 20:45:39 +0000 | [diff] [blame] | 24 | private String path_to_images; |
danielp | 54e997e | 2013-02-21 01:54:23 +0000 | [diff] [blame] | 25 | |
| 26 | private final static Logger LOG = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); |
| 27 | |
danielp | 4a35a7a | 2013-02-20 20:45:39 +0000 | [diff] [blame] | 28 | 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) { |
danielp | 54e997e | 2013-02-21 01:54:23 +0000 | [diff] [blame] | 70 | LOG.warning("Could not open file."); |
danielp | 4a35a7a | 2013-02-20 20:45:39 +0000 | [diff] [blame] | 71 | 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) { |
danielp | 54e997e | 2013-02-21 01:54:23 +0000 | [diff] [blame] | 87 | LOG.warning("Could not open file."); |
danielp | 4a35a7a | 2013-02-20 20:45:39 +0000 | [diff] [blame] | 88 | return null; |
| 89 | } |
| 90 | } |
| 91 | else |
| 92 | image_index++; |
| 93 | return null; |
| 94 | } |
| 95 | public WPIColorImage GetCurrent() { |
| 96 | return current_image; |
| 97 | } |
| 98 | } |