How to use JavaCV to realize OCR character recognition of pictures
This article introduces the relevant knowledge of "how to use JavaCV to achieve picture OCR text recognition". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Add the following dependencies to the spring boot project pom file
Org.bytedeco javacv-platform 1.5.5
Single-class code implementation, copy to the idea editor, right-click run to run.
Description of OCR method parameters
There are two types of 1.lng language: 1.eng English, 2.chi_sim, simplified Chinese.
2.dataPath language dataset folder path
The path of the picture file that 3.imagePath needs to recognize
Import org.bytedeco.javacpp.BytePointer;import org.bytedeco.leptonica.PIX;import org.bytedeco.leptonica.global.lept;import org.bytedeco.tesseract.TessBaseAPI; public class OcrTest {public static String OCR (String lng,String dataPath,String imagePath) {TessBaseAPI api=new TessBaseAPI (); if (api.Init (dataPath, lng)! = 0) {System.out.println ("error");} PIX image= lept.pixRead (imagePath) If (image==null) {return ";} api.SetImage (image); BytePointer outText=api.GetUTF8Text (); String result=outText.getString (); api.End (); outText.deallocate (); lept.pixDestroy (image); return result } public static void main (String [] args) {String text= OCR ("chi_sim", "E:\ traineddata", "C:\ Users\ tarzan\ Desktop\ image\ test5.png"); System.out.println (text);}} "how to use JavaCV to achieve picture OCR character recognition" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!