Libraries and fixed path bugs/ocr

This commit is contained in:
GrossPaul 2019-10-08 19:40:57 +02:00
parent b5b5ae276d
commit 925d7d8f6f
8 changed files with 24 additions and 27 deletions

Binary file not shown.

1
NGCC/pdf Normal file
View File

@ -0,0 +1 @@
Student number;Grade

View File

@ -5,6 +5,7 @@ import picocli.CommandLine;
import picocli.CommandLine.*; import picocli.CommandLine.*;
import progressbar.ProgressBar; import progressbar.ProgressBar;
import java.io.File;
import java.io.PrintStream; import java.io.PrintStream;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
@ -137,10 +138,11 @@ public class Read implements Callable <Void> {
Config config = new Config(source_path); //Initialise le fichier de configuration selon le chemin donné Config config = new Config(source_path); //Initialise le fichier de configuration selon le chemin donné
config.readConfig(); config.readConfig();
GestionnaireCopies ocr = new GestionnaireCopies(directory_name); // Instantie l'ocr String filePath = new File("").getAbsolutePath();
GestionnaireCopies ocr = new GestionnaireCopies("..\\"+directory_name+"\\");
// Instantie l'ocr
GenerateCSV csv = new GenerateCSV(ocr.createHashMapforCSV(),config.getParam().get("Code"), result_name, logger); GenerateCSV csv = new GenerateCSV(ocr.createHashMapforCSV(),config.getParam().get("Code"), result_name, logger);

View File

@ -50,7 +50,7 @@ public class GenerateCSV {
} }
public void createFile() { public void createFile() {
try (PrintWriter writer = new PrintWriter(new File("E:\\S3T\\Projet\\pt-s3t-g4\\pdf"))) { try (PrintWriter writer = new PrintWriter(new File("pdf"))) {
logger.info("Creating csv file"); logger.info("Creating csv file");
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();

View File

@ -1,7 +1,6 @@
package ocr; package ocr;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
@ -11,10 +10,6 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocument;
@ -36,6 +31,7 @@ public class GestionnaireCopies {
} }
applyOcr(); applyOcr();
} }
public List<BufferedImage> createImagesCopies(String path){ public List<BufferedImage> createImagesCopies(String path){
@ -49,9 +45,11 @@ public class GestionnaireCopies {
try { try {
String pdfFilesDirectory = "E:\\S3T\\Projet\\pt-s3t-g4\\pdf";
// nom du fichier pdf à ouvrir (TODO: changer le chemin) // nom du fichier pdf à ouvrir (TODO: changer le chemin)
List<String> files = pdfAnalyzer.listAllFiles(pdfFilesDirectory, ".pdf"); List<String> files = pdfAnalyzer.listAllFiles(path, ".pdf");
for (String fname : files) { for (String fname : files) {
pdfFile = new File(fname); pdfFile = new File(fname);
document = PDDocument.load(pdfFile); // charge le fichier pdf cree pour le traiter document = PDDocument.load(pdfFile); // charge le fichier pdf cree pour le traiter

View File

@ -19,7 +19,7 @@ public class ImagesCopie {
for(Img s : hMapImgs.values()) for(Img s : hMapImgs.values())
{ {
s.applyOcrImg(); s.applyOcrImg();
System.out.println("Desc : "+s.getDescription()); System.out.println("Desc : "+s.getClass().getCanonicalName()+" "+s.getDescription());
} }
} }

View File

@ -12,10 +12,10 @@ public abstract class OCR {
Tesseract tesseract = new Tesseract(); Tesseract tesseract = new Tesseract();
String str=""; String str="";
try { try {
tesseract.setDatapath("E:\\S3T\\Projet\\pt-s3t-g4\\NGCC\\Tess4J"); tesseract.setDatapath("Tess4J");
tesseract.setLanguage("eng");
//tesseract.setOcrEngineMode(2); //tesseract.setOcrEngineMode(2);
tesseract.setTessVariable("tessedit_char_whitelist","0-9"); tesseract.setTessVariable("tessedit_char_whitelist","0123456789");
str=tesseract.doOCR(img); str=tesseract.doOCR(img);
} catch (TesseractException e) { } catch (TesseractException e) {

View File

@ -30,14 +30,11 @@ public abstract class Rogneur {
int ratioX = (imgOriginale.getWidth()/595); int ratioX = (imgOriginale.getWidth()/595);
int ratioY = (imgOriginale.getWidth()/841); int ratioY = (imgOriginale.getWidth()/841);
int numEtuX1 = ratioX*((595/4)+ 4); int numEtuX1 = ratioX*((595/4)+ 4)+10;
int numEtuY1 = ratioY*115; int numEtuY1 = ratioY*115 + 275;
int numEtuX2 = ratioX*((595/4)+150); int numEtuX2 = ratioX*((595/4)+150);
int numEtuY2 = ratioY*146; int numEtuY2 = ratioY*146 + 310;
System.out.println("X1 + X2 : " +numEtuX1 + " " + numEtuX2);
System.out.println("Y1 + Y2 : " +numEtuY1 + " " + numEtuY2);
BufferedImage temp = imgOriginale.getSubimage(numEtuX1, numEtuY1, numEtuX2-numEtuX1, numEtuY2-numEtuY1); BufferedImage temp = imgOriginale.getSubimage(numEtuX1, numEtuY1, numEtuX2-numEtuX1, numEtuY2-numEtuY1);
@ -56,14 +53,13 @@ public abstract class Rogneur {
int ratioX = (imgOriginale.getWidth()/595); int ratioX = (imgOriginale.getWidth()/595);
int ratioY = (imgOriginale.getWidth()/841); int ratioY = (imgOriginale.getWidth()/841);
int numNoteX1 = ratioX*((595/4) + 4); int numNoteX1 = ratioX*((595/4) + 4)+60;
int numNoteY1 = ratioY*160; int numNoteY1 = ratioY*160+400;
int numNoteX2 = ratioX*((595/4) +80);
int numNoteY2 = ratioY*200+400;
int numNoteX2 = ratioX*((595/4) +75);
int numNoteY2 = ratioY*200;
System.out.println("X1 + X2 : " +numNoteX1 + " " + numNoteX2);
System.out.println("Y1 + Y2 : " +numNoteY1 + " " + numNoteY2);
BufferedImage temp = imgOriginale.getSubimage(numNoteX1, numNoteY1, numNoteX2-numNoteX1, numNoteY2-numNoteY1); BufferedImage temp = imgOriginale.getSubimage(numNoteX1, numNoteY1, numNoteX2-numNoteX1, numNoteY2-numNoteY1);
JFrame frame = new JFrame(); JFrame frame = new JFrame();