Helpful Articles:
HTTP://STACKOVERFLOW.COM/QUESTIONS/22014969/TESS4J-WITH-SPRING-MVC
http://stackoverflow.com/questions/ 22035048/imageio-jar-works-as-standalone-but-not-as-a-web-project
http://stackoverflow.com/questions/ 27394852/getimagewritersbyformatname-doesnt-give-proper-values
A recent tesseract-ocr-3.02+tess4j-1.5.0+servicemix-5.4.0 (a scheme based on OSGi) is always reported java.lang.RuntimeException:Need to install JAI Image I/O package
Refer to the Help file above and try constantly, and finally found the reason is need to put Jai_imageio.jar into the Jre/ext directory (my native Java address C:\Program files\java\jdk1.8.0\jre\lib\ext)
Here's a partial code:
@Override public string GetLocation (String filePath) throws IOException {bufferedimage image = null; Try {//you can either use URL or file for reading image using ImageIO File imagefile = new File ("D:
\\simplechen\\study\\osgi\\demo\\images\\1.jpg ");
Image = Imageio.read (ImageFile); ImageIO image Write Example in Java imageio.write (image, "JPG", New File ("d:\\simplechen\\study\\osgi\\demo\\t
Mp\\1.jpg "));
Imageio.write (Image, "BMP", New File ("D:\\simplechen\\study\\osgi\\demo\\tmp\\1.bmp"));
Imageio.write (image, "gif", New File ("D:\\simplechen\\study\\osgi\\demo\\tmp\\1.gif"));
Imageio.write (Image, "PNG", New File ("D:\\simplechen\\study\\osgi\\demo\\tmp\\1.png"));
catch (IOException e) {e.printstacktrace ();
} String Capctha = ""; GetLogger (). log (Logservice.log_info, "Get the picture from the local and parse it;"
Url= "+ FilePath); System.err.println ("Call getLocation" + FilePath);
File datafile = Bundlecontext.getdatafile (FilePath);
if (datafile.exists ()) {imageio.scanforplugins (); Tesseract instance = Tesseract.getinstance ();
JNA Interface Mapping System.err.println ("Verify that the environment supports TIFF");
String format= "TIF";
SYSTEM.OUT.PRINTLN (format);
Iterator<imagereader> readers = imageio.getimagereadersbyformatname (format);
System.out.println (Readers.hasnext ());
Iterator<imagewriter> writers = Imageio.getimagewritersbyformatname ("Tiff");
System.out.println (Writers.hasnext ());
try {Capctha = INSTANCE.DOOCR (datafile). Trim ();
System.err.println ("Capctha is" +capctha);
catch (Tesseractexception e) {e.printstacktrace ();
GetLogger (). log (Logservice.log_error, "Parse file" +datafile.getabsolutepath () + "failed, Cause:" +e);
} else {GetLogger (). log (Logservice.log_error, "File not Found" +filepath);
SYSTEM.ERR.PRINTLN ("File not Found");
return Capctha; }
Note:
Download Jai_imageio.jar (http://www.java2s.com/Code/Jar/j/Downloadjaiimageio11jar.htm)