本文整理汇总了Java中net.sourceforge.tess4j.TesseractException类的典型用法代码示例。如果您正苦于以下问题:Java TesseractException类的具体用法?Java TesseractException怎么用?Java TesseractException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TesseractException类属于net.sourceforge.tess4j包,在下文中一共展示了TesseractException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: map
import net.sourceforge.tess4j.TesseractException; //导入依赖的package包/类
public void map(LongWritable key, Text url, OutputCollector<Text, Text> output, Reporter reporter) throws IOException {
File videoDownloadDir = Files.createTempDir();
VGet v = new VGet(new URL(url.toString()), videoDownloadDir);
v.download();
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
File[] videoFiles = videoDownloadDir.listFiles();
Arrays.sort(videoFiles);
File[] videoFramesFiles = VideoProcessing.parseVideo(videoFiles[0], 70);
File[] processedVideoFrames = VideoProcessing.cutImages(videoFramesFiles);
Tesseract instance = Tesseract.getInstance();
instance.setDatapath("/usr/share/tesseract-ocr");
instance.setTessVariable("LC_NUMERIC", "C");
for (File image: processedVideoFrames) {
String result = null;
try {
result = instance.doOCR(image);
} catch (TesseractException e) {
e.printStackTrace();
}
if (!result.isEmpty()) {
word.set(result);
output.collect(url, word);
}
}
}
示例2: ocr
import net.sourceforge.tess4j.TesseractException; //导入依赖的package包/类
/**
*
*
* @param file
* @param originalPath
* @param language
* @return
*/
private String ocr(File file, String originalPath, String language) {
// TODO:
Tesseract1 instance = new Tesseract1();
instance.setPageSegMode(PSM_MODE);
instance.setDatapath(TESSERACT_FOLDER);
instance.setLanguage(language);
try {
String result = instance.doOCR(file);
return result;
} catch (TesseractException e) {
e.printStackTrace();
}
return null;
}
示例3: recognizeText
import net.sourceforge.tess4j.TesseractException; //导入依赖的package包/类
/**
* Zooms the text image to make it easier to read
* */
public static String recognizeText(Image image) {
LibraryLoaderSingleton.getInstance();
Image scaledImage = image.scale(8);
Tesseract instance = Tesseract.getInstance(); // JNA Interface Mapping
instance.setLanguage("eng");
System.setProperty("jna.encoding", "UTF8");
instance.setOcrEngineMode(TessAPI.TessOcrEngineMode.OEM_DEFAULT);
try {
String result = instance.doOCR(scaledImage.getInnerImage());
return result;
} catch (TesseractException e) {
throw new IllegalStateException(e);
}
catch(Exception ex){
throw new IllegalStateException("An error during text recognition was encountered.");
}
}
示例4: recognizeYText
import net.sourceforge.tess4j.TesseractException; //导入依赖的package包/类
public static String recognizeYText(Image image) {
LibraryLoaderSingleton.getInstance();
Image scaledImage = image.scale(8);
Tesseract instance = Tesseract.getInstance(); // JNA Interface Mapping
instance.setLanguage("eng");
System.setProperty("jna.encoding", "UTF8");
instance.setOcrEngineMode(TessAPI.TessOcrEngineMode.OEM_DEFAULT);
try {
String result = instance.doOCR(scaledImage.getInnerImage());
return result;
} catch (TesseractException e) {
throw new IllegalStateException(e);
}
catch(Exception ex){
throw new IllegalStateException("An error during text recognition was encountered.");
}
}
示例5: main
import net.sourceforge.tess4j.TesseractException; //导入依赖的package包/类
public static void main(String[] args) {
ITesseract instance = new Tesseract();
instance.setLanguage("eng");
try {
String result;
result = instance.doOCR(new File("OCRExample.png"));
System.out.println(result);
} catch (TesseractException e) {
System.err.println(e.getMessage());
}
}
开发者ID:PacktPublishing,项目名称:Machine-Learning-End-to-Endguide-for-Java-developers,代码行数:12,代码来源:TessrJExample.java
示例6: newAttachmentMessageEventHandler
import net.sourceforge.tess4j.TesseractException; //导入依赖的package包/类
private AttachmentMessageEventHandler newAttachmentMessageEventHandler() {
return event -> {
logger.debug("Received AttachmentMessageEvent: {}", event);
final String messageId = event.getMid();
final List<Attachment> attachments = event.getAttachments();
final String senderId = event.getSender().getId();
final Date timestamp = event.getTimestamp();
logger.info("Received message '{}' with attachments from user '{}' at '{}':",
messageId, senderId, timestamp);
attachments.forEach(attachment -> {
final AttachmentType attachmentType = attachment.getType();
final Payload payload = attachment.getPayload();
String payloadAsString = null;
if (payload.isBinaryPayload()) {
payloadAsString = payload.asBinaryPayload().getUrl();
}
if (payload.isLocationPayload()) {
payloadAsString = payload.asLocationPayload().getCoordinates().toString();
}
try {
sendTranslationOrSpellChecked(senderId, imageUrlToString(payloadAsString, "temp.png"));
} catch (TesseractException | IOException e) {
handleSendException(e);
}
logger.info("Attachment of type '{}' with payload '{}'", attachmentType, payloadAsString);
});
};
}
示例7: ocrCalcCaptcha
import net.sourceforge.tess4j.TesseractException; //导入依赖的package包/类
@Contract(pure = true)
public String ocrCalcCaptcha(@NotNull BufferedImage image) {
try {
return tesseract.doOCR(image);
} catch (TesseractException e) {
return null;
}
}
示例8: detect
import net.sourceforge.tess4j.TesseractException; //导入依赖的package包/类
@Override
public String detect(String filePath) {
File imageFile = new File(filePath);
Tesseract tess = new Tesseract();
tess.setLanguage("hun");
try {
String result = tess.doOCR(imageFile);
return result;
} catch (TesseractException e) {
return "ERROR";
}
}
示例9: getConvertedBoard
import net.sourceforge.tess4j.TesseractException; //导入依赖的package包/类
public static char[][] getConvertedBoard(BufferedImage[] tiles) throws TesseractException {
Tesseract reader = new Tesseract();
char[][] ret = new char[Player.BOARD_HEIGHT][Player.BOARD_WIDTH];
BufferedImage processedImage;
String convertedTile;
for(int j = 0; j < Player.BOARD_HEIGHT; j++) {
for(int k = 0; k < Player.BOARD_WIDTH; k++) {
processedImage = ImageHelper.convertImageToGrayscale(tiles[j*Player.BOARD_HEIGHT+k]);
convertedTile = reader.doOCR(processedImage);
ret[j][k] = BoardConstructor.getLastAlpha(convertedTile);
}
}
return ret;
}
示例10: OCR
import net.sourceforge.tess4j.TesseractException; //导入依赖的package包/类
public String OCR(SerializableImage image) {
try {
String hh = Tesseract.getInstance().doOCR(image.getImage());
// System.out.println(hh);
log.info("Read: " + hh);
return hh;
} catch (TesseractException e) {
e.printStackTrace();
}
return null;
}
示例11: ocr
import net.sourceforge.tess4j.TesseractException; //导入依赖的package包/类
public static String ocr(File file) {
Tesseract instance = Tesseract.getInstance(); // JNA Interface Mapping
instance.setDatapath(tessdataPath);
instance.setLanguage("eng");
//instance.setLanguage("number");
String result = "";
try {
result = instance.doOCR(file);
} catch (TesseractException e) {
System.err.println(e.getMessage());
} finally {
}
return result;
}
示例12: ocr
import net.sourceforge.tess4j.TesseractException; //导入依赖的package包/类
public String ocr(BufferedImage image) {
try {
String hh = Tesseract.getInstance().doOCR(image);
// System.out.println(hh);
log.info("Read: " + hh);
return hh;
} catch (TesseractException e) {
e.printStackTrace();
}
return null;
}
示例13: recognizeXText
import net.sourceforge.tess4j.TesseractException; //导入依赖的package包/类
public static String recognizeXText(Image image) {
LibraryLoaderSingleton.getInstance();
Tesseract instance = Tesseract.getInstance(); // JNA Interface Mapping
instance.setOcrEngineMode(TessAPI.TessOcrEngineMode.OEM_TESSERACT_ONLY);
BufferedImage img = getScaledImage(image.getInnerImage(), image.getInnerImage().getWidth()*2, image.getInnerImage().getHeight()*2);
img = thresholdImage(img, 165);
try {
String result = instance.doOCR(img);
return result;
} catch (TesseractException e) {
throw new IllegalStateException(e);
}
catch(Exception ex){
throw new IllegalStateException("An error during text recognition was encountered.");
}
}
示例14: read
import net.sourceforge.tess4j.TesseractException; //导入依赖的package包/类
public String read(Picture picture) {
if (valid) {
try {
return tess.doOCR(picture.get());
} catch (TesseractException e) {
log.error("read: %s", e.getMessage());
}
} else {
log.error("read: TextFinder not valid");
}
return "did not work";
}
示例15: doOcrFile
import net.sourceforge.tess4j.TesseractException; //导入依赖的package包/类
@RequestMapping(value = "ocr/v0.9/upload", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public Status doOcrFile(@RequestBody final Image image) throws Exception {
File tmpFile = File.createTempFile("ocr_image", image.getExtension());
try {
FileUtils.writeByteArrayToFile(tmpFile, Base64.decodeBase64(image.getImage()));
Tesseract tesseract = Tesseract.getInstance(); // JNA Interface Mapping
String imageText = tesseract.doOCR(tmpFile);
LOGGER.debug("OCR Image Text = " + imageText);
} catch (Exception e) {
LOGGER.error("Exception while converting/uploading image: ", e);
throw new TesseractException();
} finally {
tmpFile.delete();
}
return new Status("success");
}