diff --git a/NGCC/src/ocr/Copie.java b/NGCC/src/ocr/Copie.java new file mode 100644 index 0000000..583bed6 --- /dev/null +++ b/NGCC/src/ocr/Copie.java @@ -0,0 +1,22 @@ +package ocr; + +import java.awt.image.BufferedImage; + +public class Copie { + + ImagesCopie base; + + public Copie(BufferedImage img) { + this.base = new ImagesCopie(img); + } + + public ImagesCopie getBase() { + return base; + } + + public void setBase(ImagesCopie base) { + this.base = base; + } + + +} diff --git a/NGCC/src/ocr_orm/ControleurOCR.java b/NGCC/src/ocr/GestionnaireCopies.java similarity index 56% rename from NGCC/src/ocr_orm/ControleurOCR.java rename to NGCC/src/ocr/GestionnaireCopies.java index 3016f32..6971731 100644 --- a/NGCC/src/ocr_orm/ControleurOCR.java +++ b/NGCC/src/ocr/GestionnaireCopies.java @@ -1,26 +1,40 @@ -package ocr_orm; +package ocr; + import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; - +import java.util.Map; import org.apache.pdfbox.pdmodel.PDDocument; -public class ControleurOCR { - public HashMap getNumNote(String path){ +public class GestionnaireCopies { + + private List listeCopie; + + private List copies; + + public GestionnaireCopies(String chemin) { + + copies = createImagesCopies(chemin); + listeCopie = new ArrayList(); + + for(BufferedImage i : copies) + { + listeCopie.add(new Copie(i)); + } + } + + public List createImagesCopies(String path){ PdfToImage pdfAnalyzer = new PdfToImage(); File pdfFile; PDDocument document = null; //LISTE DES IMAGES - ArrayList images = new ArrayList<>(); // stockera les images (resultat) - //HASHMAP POUR LE CSV - HashMap listeNumNote = new HashMap(); - + List images = new ArrayList<>(); // stockera les images (resultat) // CONVERT PAGES TO IMAGES try { String pdfFilesDirectory = "C:\\Users\\ph807242\\eclipse-workspace\\PT\\pdf\\"; @@ -37,10 +51,20 @@ public class ControleurOCR { } //LISTE DES IMAGES COMPRENANT L'IMAGE DE LA NOTE ET DU NUM ETUDIANT - ListeImageNGCC liNGCC = new ListeImageNGCC(images); - - listeNumNote = liNGCC.doOCR(); - return listeNumNote; + + return images; } + + public Map createHashMapforCSV(){ + + Map temp = new HashMap<>(); + for(Copie c : listeCopie) + { + temp.put(c.getBase().gethMapImgs().get("NumEtu").getDescription(), c.getBase().gethMapImgs().get("Note").getDescription()); + } + return temp; + + } + } diff --git a/NGCC/src/ocr/ImagesCopie.java b/NGCC/src/ocr/ImagesCopie.java new file mode 100644 index 0000000..1414cf6 --- /dev/null +++ b/NGCC/src/ocr/ImagesCopie.java @@ -0,0 +1,34 @@ +package ocr; + +import java.awt.image.BufferedImage; +import java.util.Map; + +public class ImagesCopie { + + private Map hMapImgs; + + + public ImagesCopie(BufferedImage imgOriginale) { + + + hMapImgs = Rogneur.createHMapImgs(imgOriginale); + } + + public void applyOcrForEach() { + + for(String s : hMapImgs.keySet()) + { + hMapImgs.get(s).applyOcrImg(); + } + } + + public Map gethMapImgs() { + return hMapImgs; + } + + public void sethMapImgs(Map hMapImgs) { + this.hMapImgs = hMapImgs; + } + + +} diff --git a/NGCC/src/ocr/Img.java b/NGCC/src/ocr/Img.java new file mode 100644 index 0000000..3647c45 --- /dev/null +++ b/NGCC/src/ocr/Img.java @@ -0,0 +1,37 @@ +package ocr; + +import java.awt.image.BufferedImage; + +public abstract class Img { + + BufferedImage img; + String description; + + public Img(BufferedImage img) { + + this.img = img; + + } + + public abstract void applyOcrImg(); + + public BufferedImage getImg() { + return img; + } + + public void setImg(BufferedImage img) { + this.img = img; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + + + +} diff --git a/NGCC/src/ocr/ImgNote.java b/NGCC/src/ocr/ImgNote.java new file mode 100644 index 0000000..bdc4db6 --- /dev/null +++ b/NGCC/src/ocr/ImgNote.java @@ -0,0 +1,19 @@ +package ocr; + +import java.awt.image.BufferedImage; + + + +public class ImgNote extends Img{ + + public ImgNote(BufferedImage img) { + super(img); + // TODO Auto-generated constructor stub + } + + @Override + public void applyOcrImg() { + setDescription(OCR.applyOcrNumber(getImg())); + } + +} diff --git a/NGCC/src/ocr/ImgNumEtu.java b/NGCC/src/ocr/ImgNumEtu.java new file mode 100644 index 0000000..c32f08a --- /dev/null +++ b/NGCC/src/ocr/ImgNumEtu.java @@ -0,0 +1,18 @@ +package ocr; + +import java.awt.image.BufferedImage; + + + +public class ImgNumEtu extends Img{ + + public ImgNumEtu(BufferedImage img) { + super(img); + } + + @Override + public void applyOcrImg() { + setDescription(OCR.applyOcrNumber(getImg())); + } + +} \ No newline at end of file diff --git a/NGCC/src/ocr_orm/OCR.java b/NGCC/src/ocr/OCR.java similarity index 75% rename from NGCC/src/ocr_orm/OCR.java rename to NGCC/src/ocr/OCR.java index 8db7c89..96cf264 100644 --- a/NGCC/src/ocr_orm/OCR.java +++ b/NGCC/src/ocr/OCR.java @@ -1,4 +1,4 @@ -package ocr_orm; +package ocr; import java.awt.image.BufferedImage; @@ -9,13 +9,13 @@ public class OCR { - public String getOCR(BufferedImage img) { + public static String applyOcrNumber(BufferedImage img) { //FAIRE L'OCR Tesseract tesseract = new Tesseract(); String str=""; try { tesseract.setOcrEngineMode(2); - tesseract.setTessVariable("tessedit_char_whitelist", "A-Za-z1-9"); + tesseract.setTessVariable("tessedit_char_whitelist","0-9"); str=tesseract.doOCR(img); } catch (TesseractException e) { diff --git a/NGCC/src/ocr_orm/PdfToImage.java b/NGCC/src/ocr/PdfToImage.java similarity index 99% rename from NGCC/src/ocr_orm/PdfToImage.java rename to NGCC/src/ocr/PdfToImage.java index 6c6f8e7..b80295b 100644 --- a/NGCC/src/ocr_orm/PdfToImage.java +++ b/NGCC/src/ocr/PdfToImage.java @@ -1,4 +1,4 @@ -package ocr_orm; +package ocr; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; diff --git a/NGCC/src/ocr/Rogneur.java b/NGCC/src/ocr/Rogneur.java new file mode 100644 index 0000000..1826bb2 --- /dev/null +++ b/NGCC/src/ocr/Rogneur.java @@ -0,0 +1,43 @@ +package ocr; + +import java.awt.image.BufferedImage; +import java.util.HashMap; +import java.util.Map; + +public class Rogneur { + + // Retourne une hashmap contenant une image et la description de son contenu + public static Map createHMapImgs(BufferedImage imgOriginale) { + + Map temp = new HashMap<>(); + temp.put("NumEtu", rogneurNumEtu(imgOriginale)); + temp.put("Note", rogneurNote(imgOriginale)); + //temp.put("FormatNote", rogneurFormatNote(imgOriginale)); + + return temp; + } + + // rogne la partie du numEtu + public static Img rogneurNumEtu(BufferedImage imgOriginale) + { + return (new ImgNumEtu(imgOriginale.getSubimage((imgOriginale.getWidth()/4)+4 + , imgOriginale.getHeight()-imgOriginale.getHeight()+115 + , (imgOriginale.getWidth()/4+150)-(imgOriginale.getWidth()/4+4) + , imgOriginale.getHeight()-imgOriginale.getHeight()+146-(imgOriginale.getHeight()-imgOriginale.getHeight()+115) ))); + } + + // rogne la partie de la note + public static Img rogneurNote(BufferedImage imgOriginale) + { + return (new ImgNumEtu(imgOriginale.getSubimage((imgOriginale.getWidth()/4)+4 + , imgOriginale.getHeight()-imgOriginale.getHeight()+160 + , (imgOriginale.getWidth()/4+150)-(imgOriginale.getWidth()/4+4) + , imgOriginale.getHeight()-imgOriginale.getHeight()+200-(imgOriginale.getHeight()-imgOriginale.getHeight()+160) ))); + } + + // rogne la partie du format de la note + /*public static Img rogneurFormatNote(BufferedImage imgOriginale) + { + 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..de3b52c --- /dev/null +++ b/NGCC/src/ocr/diag.ucls @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/NGCC/src/ocr_orm/ImageNGCC.java b/NGCC/src/ocr_orm/ImageNGCC.java deleted file mode 100644 index d1755e0..0000000 --- a/NGCC/src/ocr_orm/ImageNGCC.java +++ /dev/null @@ -1,37 +0,0 @@ -package ocr_orm; - -import java.awt.image.*; - -import javax.imageio.ImageIO; - -import org.apache.pdfbox.rendering.ImageType; - -import java.awt.Image; -@SuppressWarnings("unused") -public class ImageNGCC { - - BufferedImage imgcopie ; - BufferedImage imgNumEtu; - BufferedImage imgNote; - - public ImageNGCC(BufferedImage buf){ - imgcopie=buf; - imgNumEtu = imgcopie.getSubimage(0,0, 100, 50); - imgNote = imgcopie.getSubimage(50,50,100,50); - } - - public BufferedImage getImgNumEtu() { - return imgNumEtu; - } - - public BufferedImage getImgNote() { - return imgNote; - } - - - - - - -} -//https://docs.oracle.com/javase/tutorial/2d/images/drawimage.html \ No newline at end of file diff --git a/NGCC/src/ocr_orm/ListeImageNGCC.java b/NGCC/src/ocr_orm/ListeImageNGCC.java deleted file mode 100644 index 1db1505..0000000 --- a/NGCC/src/ocr_orm/ListeImageNGCC.java +++ /dev/null @@ -1,46 +0,0 @@ -package ocr_orm; - - -import java.awt.image.BufferedImage; -import java.util.ArrayList; -import java.util.HashMap; -; - - - -public class ListeImageNGCC { - - private ArrayList listeImage = new ArrayList(); - - - public ListeImageNGCC(ArrayList liste) { - - for(int i=0; i getListeImage(ArrayList liste) { - return listeImage; - } - - public int taille() { - return listeImage.size(); - } - - public HashMap doOCR(){ - HashMap maMap = new HashMap(); - OCR ocr = new OCR(); - for (int i=0;i