Merging ocr into master
This commit is contained in:
commit
31ecad7798
22
NGCC/src/ocr/Copie.java
Normal file
22
NGCC/src/ocr/Copie.java
Normal file
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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<String,String> getNumNote(String path){
|
||||
public class GestionnaireCopies {
|
||||
|
||||
private List<Copie> listeCopie;
|
||||
|
||||
private List<BufferedImage> copies;
|
||||
|
||||
public GestionnaireCopies(String chemin) {
|
||||
|
||||
copies = createImagesCopies(chemin);
|
||||
listeCopie = new ArrayList<Copie>();
|
||||
|
||||
for(BufferedImage i : copies)
|
||||
{
|
||||
listeCopie.add(new Copie(i));
|
||||
}
|
||||
}
|
||||
|
||||
public List<BufferedImage> createImagesCopies(String path){
|
||||
|
||||
PdfToImage pdfAnalyzer = new PdfToImage();
|
||||
File pdfFile;
|
||||
PDDocument document = null;
|
||||
//LISTE DES IMAGES
|
||||
ArrayList<BufferedImage> images = new ArrayList<>(); // stockera les images (resultat)
|
||||
//HASHMAP POUR LE CSV
|
||||
HashMap<String,String> listeNumNote = new HashMap<String, String>();
|
||||
|
||||
List<BufferedImage> 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<String,String> createHashMapforCSV(){
|
||||
|
||||
Map<String,String> temp = new HashMap<>();
|
||||
for(Copie c : listeCopie)
|
||||
{
|
||||
temp.put(c.getBase().gethMapImgs().get("NumEtu").getDescription(), c.getBase().gethMapImgs().get("Note").getDescription());
|
||||
}
|
||||
return temp;
|
||||
|
||||
}
|
||||
|
||||
}
|
34
NGCC/src/ocr/ImagesCopie.java
Normal file
34
NGCC/src/ocr/ImagesCopie.java
Normal file
@ -0,0 +1,34 @@
|
||||
package ocr;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Map;
|
||||
|
||||
public class ImagesCopie {
|
||||
|
||||
private Map<String,Img> hMapImgs;
|
||||
|
||||
|
||||
public ImagesCopie(BufferedImage imgOriginale) {
|
||||
|
||||
|
||||
hMapImgs = Rogneur.createHMapImgs(imgOriginale);
|
||||
}
|
||||
|
||||
public void applyOcrForEach() {
|
||||
|
||||
for(String s : hMapImgs.keySet())
|
||||
{
|
||||
hMapImgs.get(s).applyOcrImg();
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, Img> gethMapImgs() {
|
||||
return hMapImgs;
|
||||
}
|
||||
|
||||
public void sethMapImgs(Map<String, Img> hMapImgs) {
|
||||
this.hMapImgs = hMapImgs;
|
||||
}
|
||||
|
||||
|
||||
}
|
37
NGCC/src/ocr/Img.java
Normal file
37
NGCC/src/ocr/Img.java
Normal file
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
19
NGCC/src/ocr/ImgNote.java
Normal file
19
NGCC/src/ocr/ImgNote.java
Normal file
@ -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()));
|
||||
}
|
||||
|
||||
}
|
18
NGCC/src/ocr/ImgNumEtu.java
Normal file
18
NGCC/src/ocr/ImgNumEtu.java
Normal file
@ -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()));
|
||||
}
|
||||
|
||||
}
|
@ -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) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package ocr_orm;
|
||||
package ocr;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
43
NGCC/src/ocr/Rogneur.java
Normal file
43
NGCC/src/ocr/Rogneur.java
Normal file
@ -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<String, Img> createHMapImgs(BufferedImage imgOriginale) {
|
||||
|
||||
Map<String,Img> 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);
|
||||
}*/
|
||||
}
|
97
NGCC/src/ocr/diag.ucls
Normal file
97
NGCC/src/ocr/diag.ucls
Normal file
@ -0,0 +1,97 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<class-diagram version="1.2.3" icons="true" always-add-relationships="false" generalizations="true" realizations="true"
|
||||
associations="true" dependencies="false" nesting-relationships="true" router="FAN">
|
||||
<class id="1" language="java" name="ocr.ImgNumEtu" project="PT" file="/PT/src/ocr/ImgNumEtu.java" binary="false"
|
||||
corner="BOTTOM_RIGHT">
|
||||
<position height="99" width="157" x="309" y="901"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||
sort-features="false" accessors="true" visibility="true">
|
||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="2" language="java" name="ocr.Img" project="PT" file="/PT/src/ocr/Img.java" binary="false"
|
||||
corner="BOTTOM_RIGHT">
|
||||
<position height="207" width="159" x="407" y="654"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||
sort-features="false" accessors="true" visibility="true">
|
||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="3" language="java" name="ocr.Rogneur" project="PT" file="/PT/src/ocr/Rogneur.java" binary="false"
|
||||
corner="BOTTOM_RIGHT">
|
||||
<position height="153" width="267" x="100" y="322"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||
sort-features="false" accessors="true" visibility="true">
|
||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="4" language="java" name="ocr.Copie" project="PT" file="/PT/src/ocr/Copie.java" binary="false"
|
||||
corner="BOTTOM_RIGHT">
|
||||
<position height="81" width="87" x="407" y="322"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||
sort-features="false" accessors="true" visibility="true">
|
||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="5" language="java" name="ocr.ImgNote" project="PT" file="/PT/src/ocr/ImgNote.java" binary="false"
|
||||
corner="BOTTOM_RIGHT">
|
||||
<position height="99" width="143" x="506" y="901"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||
sort-features="false" accessors="true" visibility="true">
|
||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="6" language="java" name="ocr.OCR" project="PT" file="/PT/src/ocr/OCR.java" binary="false"
|
||||
corner="BOTTOM_RIGHT">
|
||||
<position height="99" width="217" x="534" y="322"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||
sort-features="false" accessors="true" visibility="true">
|
||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="7" language="java" name="ocr.ImagesCopie" project="PT" file="/PT/src/ocr/ImagesCopie.java" binary="false"
|
||||
corner="BOTTOM_RIGHT">
|
||||
<position height="99" width="166" x="407" y="515"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||
sort-features="false" accessors="true" visibility="true">
|
||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||
</display>
|
||||
</class>
|
||||
<generalization id="8">
|
||||
<end type="SOURCE" refId="1"/>
|
||||
<end type="TARGET" refId="2"/>
|
||||
</generalization>
|
||||
<association id="9">
|
||||
<end type="SOURCE" refId="7" navigable="false">
|
||||
<attribute id="10" name="hMapImgs"/>
|
||||
<multiplicity id="11" minimum="0" maximum="2147483647"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="2" navigable="true"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<generalization id="12">
|
||||
<end type="SOURCE" refId="5"/>
|
||||
<end type="TARGET" refId="2"/>
|
||||
</generalization>
|
||||
<association id="13">
|
||||
<end type="SOURCE" refId="4" navigable="false">
|
||||
<attribute id="14" name="base"/>
|
||||
<multiplicity id="15" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="7" navigable="true"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||
sort-features="false" accessors="true" visibility="true">
|
||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||
</classifier-display>
|
||||
<association-display labels="true" multiplicity="true"/>
|
||||
</class-diagram>
|
@ -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
|
@ -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<ImageNGCC> listeImage = new ArrayList<ImageNGCC>();
|
||||
|
||||
|
||||
public ListeImageNGCC(ArrayList<BufferedImage> liste) {
|
||||
|
||||
for(int i=0; i<liste.size();i++)
|
||||
{
|
||||
//ON AJOUTE UNE IMAGE NGCC CREE A PARTIR DE CHAQUE IMAGE DE LA LISTE D'IMAGE BUF
|
||||
listeImage.add(new ImageNGCC(liste.get(i)) );
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<ImageNGCC> getListeImage(ArrayList<BufferedImage> liste) {
|
||||
return listeImage;
|
||||
}
|
||||
|
||||
public int taille() {
|
||||
return listeImage.size();
|
||||
}
|
||||
|
||||
public HashMap<String, String> doOCR(){
|
||||
HashMap<String,String> maMap = new HashMap<String, String>();
|
||||
OCR ocr = new OCR();
|
||||
for (int i=0;i<listeImage.size();i++) {
|
||||
String strNote;
|
||||
String strNumEtu;
|
||||
strNote = ocr.getOCR(listeImage.get(i).getImgNote());
|
||||
strNumEtu = ocr.getOCR(listeImage.get(i).getImgNumEtu());
|
||||
maMap.put(strNumEtu, strNote);
|
||||
}
|
||||
return maMap;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user