|
|
|
@@ -118,15 +118,24 @@ public class FormallTess4j { |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
private static void deletetempFile(File file) { |
|
|
|
if (file.exists()) { |
|
|
|
file.delete(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static String ocrLocalImgFile(String filePath) throws Exception { |
|
|
|
public static String ocrLocalImgFile(String filePath,String dataPath) throws Exception { |
|
|
|
File imageFile = new File(filePath); |
|
|
|
return testDoOCR_File(imageFile); |
|
|
|
String result = testDoOCR_File(imageFile,dataPath); |
|
|
|
deletetempFile(imageFile); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
public static String ocrNetImgFile(String fileUrl) throws Exception { |
|
|
|
public static String ocrNetImgFile(String fileUrl,String dataPath) throws Exception { |
|
|
|
File imageFile = urlImgToFile(fileUrl); |
|
|
|
return testDoOCR_File(imageFile); |
|
|
|
String result = testDoOCR_File(imageFile,dataPath); |
|
|
|
deletetempFile(imageFile); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
@@ -134,10 +143,10 @@ public class FormallTess4j { |
|
|
|
* 根据图片文件进行识别 |
|
|
|
* @throws Exception while processing image. |
|
|
|
*/ |
|
|
|
private static String testDoOCR_File(File imageFile) throws Exception { |
|
|
|
private static String testDoOCR_File(File imageFile,String dataPath) throws Exception { |
|
|
|
logger.info("doOCR on a jpg image"); |
|
|
|
//set language |
|
|
|
instance.setDatapath(testResourcesLanguagePath); |
|
|
|
instance.setDatapath(dataPath); |
|
|
|
instance.setLanguage("chi_sim"); |
|
|
|
String result = instance.doOCR(imageFile); |
|
|
|
return result; |
|
|
|
@@ -146,7 +155,7 @@ public class FormallTess4j { |
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
try { |
|
|
|
System.out.println(ocrNetImgFile("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.my0832.com%2Fattachments%2Fbbs%2F20140424%2F201442413083356803_740_1186.jpg&refer=http%3A%2F%2Fimg.my0832.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1613903848&t=985fc4c6c7b7ee82cb98f97ab5bf1459")); |
|
|
|
System.out.println(ocrNetImgFile("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.my0832.com%2Fattachments%2Fbbs%2F20140424%2F201442413083356803_740_1186.jpg&refer=http%3A%2F%2Fimg.my0832.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1613903848&t=985fc4c6c7b7ee82cb98f97ab5bf1459",testResourcesLanguagePath)); |
|
|
|
} catch (Exception e) { |
|
|
|
// TODO Auto-generated catch block |
|
|
|
e.printStackTrace(); |
|
|
|
|