// Last edited on 2013-01-04 17:21:25 by stolfilocal package main; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.PrintStream; import java.util.List; import java.awt.image.BufferedImage; import javax.imageio.ImageIO; import thog.thog_desc; import utils.FloatImage; import xml.fields; import xml.parser; import xml.register; public class extraction { static void extract_image_subregions ( List xml_regions, String image_path, String image_type, String out_path ) { thog_desc thog = new thog_desc (); int xml_size = xml_regions.size(); for(int index = 0; index < xml_size; index++) { register regions = xml_regions.get(index); BufferedImage image = null; String image_name = null; try { image_name = image_path + regions.get_image_name() + image_type; image = ImageIO.read(new File(image_name)); } catch (Exception e) { System.err.printf("error: fail to open image: %s\n", image_name); System.exit(1); } for (int text_region_index = 0; text_region_index < regions.get_nregions(); text_region_index++) { fields text_region = regions.get_region (text_region_index); int x = (int) text_region.get_x(); int y = (int) text_region.get_y(); int w = (int) text_region.get_w(); int h = (int) text_region.get_h(); FloatImage candidate = thog.get_thog_sub_image (image, x, y, w, h); try { ImageIO.write (candidate, "png", new File(out_path + "2_" + regions.get_image_name() + "_" + String.format("%03d", text_region_index) + ".png")); } catch (Exception e) { System.err.printf("Cannot write image %s\n"); } } } } public static void main (String[] args) throws Exception { if (args.length < 3) { System.err.printf("use: java -ea -cp thog.jar \\ \n main.extraction \\ \n {xml_in} [icdar format] \\ \n {image_path} \\ \n {image_type} [png/jpg] \n"); return; } List xml_regions = parser.run (args[0]); String image_path = args[1]; String out_path = args[2]; String image_type = args[3]; extract_image_subregions (xml_regions, image_path, image_type, out_path); } }