"Java.lang.RuntimeException:Need to install JAI Image I/O package has been reported under the Tesseract OSGi environment." The solution

Source: Internet
Author: User
Tags string format

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.