From 5b062f11d7d32e2ea85f4e0be439a3c0bfadf134 Mon Sep 17 00:00:00 2001 From: Hugo Date: Fri, 27 Sep 2019 08:51:47 +0200 Subject: [PATCH] Ajout d'un ocr plus agile --- NGCC/src/ocr/ImagesCopie.java | 1 + NGCC/src/ocr/ImgNote.java | 4 ++-- NGCC/src/ocr/ImgNumEtu.java | 4 ++-- NGCC/src/ocr/OCR.java | 28 ++++++++++++++++++++++++++++ NGCC/src/ocr/Rogneur.java | 24 +++++++++--------------- NGCC/src/ocr/diag.ucls | 10 ++++++++++ 6 files changed, 52 insertions(+), 19 deletions(-) create mode 100644 NGCC/src/ocr/OCR.java create mode 100644 NGCC/src/ocr/diag.ucls diff --git a/NGCC/src/ocr/ImagesCopie.java b/NGCC/src/ocr/ImagesCopie.java index 261ef89..39bb319 100644 --- a/NGCC/src/ocr/ImagesCopie.java +++ b/NGCC/src/ocr/ImagesCopie.java @@ -10,6 +10,7 @@ public abstract class ImagesCopie { public ImagesCopie(BufferedImage imgOriginale) { + hMapImgs = Rogneur.createHMapImgs(imgOriginale); } diff --git a/NGCC/src/ocr/ImgNote.java b/NGCC/src/ocr/ImgNote.java index d923d09..bdc4db6 100644 --- a/NGCC/src/ocr/ImgNote.java +++ b/NGCC/src/ocr/ImgNote.java @@ -2,7 +2,7 @@ package ocr; import java.awt.image.BufferedImage; -import ocr_orm.OCR; + public class ImgNote extends Img{ @@ -13,7 +13,7 @@ public class ImgNote extends Img{ @Override public void applyOcrImg() { - setDescription(OCR.applyOcrNumber(getImg()));; + setDescription(OCR.applyOcrNumber(getImg())); } } diff --git a/NGCC/src/ocr/ImgNumEtu.java b/NGCC/src/ocr/ImgNumEtu.java index 04b63d2..c32f08a 100644 --- a/NGCC/src/ocr/ImgNumEtu.java +++ b/NGCC/src/ocr/ImgNumEtu.java @@ -2,7 +2,7 @@ package ocr; import java.awt.image.BufferedImage; -import ocr_orm.OCR; + public class ImgNumEtu extends Img{ @@ -12,7 +12,7 @@ public class ImgNumEtu extends Img{ @Override public void applyOcrImg() { - setDescription(OCR.applyOcrNumber(getImg()));; + setDescription(OCR.applyOcrNumber(getImg())); } } \ No newline at end of file diff --git a/NGCC/src/ocr/OCR.java b/NGCC/src/ocr/OCR.java new file mode 100644 index 0000000..96cf264 --- /dev/null +++ b/NGCC/src/ocr/OCR.java @@ -0,0 +1,28 @@ +package ocr; +import java.awt.image.BufferedImage; + + +import net.sourceforge.tess4j.Tesseract; +import net.sourceforge.tess4j.TesseractException; + +public class OCR { + + + + public static String applyOcrNumber(BufferedImage img) { + //FAIRE L'OCR + Tesseract tesseract = new Tesseract(); + String str=""; + try { + tesseract.setOcrEngineMode(2); + tesseract.setTessVariable("tessedit_char_whitelist","0-9"); + str=tesseract.doOCR(img); + } catch (TesseractException e) { + + e.printStackTrace(); + } + + + return str; + } +} diff --git a/NGCC/src/ocr/Rogneur.java b/NGCC/src/ocr/Rogneur.java index 5bacf55..3063b9a 100644 --- a/NGCC/src/ocr/Rogneur.java +++ b/NGCC/src/ocr/Rogneur.java @@ -10,34 +10,28 @@ public class Rogneur { public static Map createHMapImgs(BufferedImage imgOriginale) { Map temp = new HashMap<>(); - temp.put("NumEtu", rogneurFormatNote(BufferedImage imgOriginale)); - temp.put("Note", rogneurFormatNote(BufferedImage imgOriginale)); - temp.put("FormatNote", rogneurFormatNote(BufferedImage imgOriginale)); + temp.put("NumEtu", rogneurFormatNote(imgOriginale)); + temp.put("Note", rogneurFormatNote(imgOriginale)); + temp.put("FormatNote", rogneurFormatNote(imgOriginale)); return temp; } // rogne la partie du numEtu - public Img rogneurNumEtu(BufferedImage imgOriginale) + public static Img rogneurNumEtu(BufferedImage imgOriginale) { - - // A FAIRE - //return new ImgNum(); + return imgOriginale.getSubimage(x, y, w, h); } // rogne la partie de la note - public Img rogneurNote(BufferedImage imgOriginale) + public static Img rogneurNote(BufferedImage imgOriginale) { - - // A FAIRE - //return new ImgNum(); + return imgOriginale.getSubimage(x, y, w, h); } // rogne la partie du format de la note - public Img rogneurFormatNote(BufferedImage imgOriginale) + public static Img rogneurFormatNote(BufferedImage imgOriginale) { - - // A FAIRE - //return new ImgNum(); + return imgOriginale.getSubimage(x, y, w, h); } } diff --git a/NGCC/src/ocr/diag.ucls b/NGCC/src/ocr/diag.ucls new file mode 100644 index 0000000..720ffbe --- /dev/null +++ b/NGCC/src/ocr/diag.ucls @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file