diff --git a/NGCC/src/lecturePdf/Recadrage.java b/NGCC/src/lecturePdf/Recadrage.java index 28f1c0c..0ac0dba 100644 --- a/NGCC/src/lecturePdf/Recadrage.java +++ b/NGCC/src/lecturePdf/Recadrage.java @@ -1,37 +1,50 @@ package lecturePdf; import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; +import java.awt.image.AffineTransformOp; +import java.awt.image.BufferedImage; + + import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + import javax.imageio.ImageIO; + public class Recadrage { - String dir=""; - String filename=""; - BufferedImage img; - - - public Recadrage(String directory,String file) { - dir=directory; - filename=file; - File f =new File(dir+filename); - - try { - img=ImageIO.read(f); - } catch (IOException e) { - System.out.println(e); - } - } - - public boolean estDroite() { //determine si l'image png/jpg du pdf est droite + String dir=""; + String filename=""; + BufferedImage img; + + + public Recadrage(String directory,String file) { + dir=directory; + filename=file; + File f =new File(dir+filename); + try { + img=ImageIO.read(f); + } catch (IOException e) { + //System.out.println(e); + } + } + + public Recadrage(BufferedImage image) { + img=image; + } + + public boolean estDroite() { //determine si l'image png/jpg du pdf est droite (doit etre en noir et blanc) int count=0; boolean stop=false; for (int ty=0; ty<100 && !stop;ty++) { for (int tx=0;tximg.getWidth()/5.4 && count 5 ou y-(y-1)>5 + roar2[tmp][0]=roar[l][0]; //efface le precedent roar2 si il était a 1 pixel de diff + roar2[tmp][1]=roar[l][1]; + } + else { + tmp++; + roar2[tmp]=roar[l]; + } + + } + + //boucle de determination des points noirs + //System.out.println("roar2debut"); + int points[][]=new int [4][2]; + int lastRoar[][]=new int [roar2.length][2]; int boucl=0; int lasti=0; + int t=0; + for (int l=1;l<=img.getHeight()*img.getWidth() && (roar2[l-1][1]!=0 || roar2[l-1][0]!=0);l++) { + + + + int diffx=roar2[l][0]-roar2[l-1][0]; + int diffy=roar2[l][1]-roar2[l-1][1]; + int diff=Math.abs(diffx)+Math.abs(diffy); + if (diff>img.getWidth()*0.85) + { + points[t]=roar2[l]; + t++; + } + + if (diffx<10 && diffy<10) { + boucl++; + } + else { + lastRoar[lasti][0]=roar2[l-boucl/2][0]; + lastRoar[lasti][1]=roar2[l-boucl/2][1]; + lasti++;boucl=0; + } + } + + + + //System.out.println("lasrorar"); + for (int l=0;l<=lastRoar.length && (lastRoar[l][1]!=0 || lastRoar[l][0]!=0);l++) { + //System.out.println("x: "+lastRoar[l][0]+" y: "+lastRoar[l][1]); //reste a grouper les coord pour avoir le centre des ronds + } + + + + for (int l=0;l<=lastRoar.length && (lastRoar[l][1]!=0 || lastRoar[l][0]!=0);l++) { + boolean test=true; + int maxPoint=0; + for (int li=0;li<=points.length && (points[li][1]!=0 || points[li][0]!=0);li++) { + int diffx= Math.abs(lastRoar[l][0]-points[li][0]); + int diffy= Math.abs(lastRoar[l][1]-points[li][1]); + boolean testx= diffx>img.getWidth()*0.85 || diffx0.8 x la largeur de feuille + boolean testy= diffy>img.getHeight()*0.8 || diffyimg.getWidth()*0.2; //si point deja présent + + if (!Repeat || (!testx || !testy) ) // si 0.2>diffx>0.8 ou "diffy" et + { + test=false; + } + maxPoint=li; + } + + if(test && maxPoint<2) { + //System.out.println(lastRoar[l][0]+" "+lastRoar[l][1]); + points[maxPoint+1][0]=lastRoar[l][0]; + points[maxPoint+1][1]=lastRoar[l][1]; + } + } + //System.out.println("point"); + for (int l=1;l<=points.length;l++) { + System.out.println("x: "+points[l-1][0]+" y: "+points[l-1][1]); + } + + return points; + + } + + + + + + + public boolean checkCircle(int x,int y,int radius) { + double pi=Math.PI; //3.14 + Color tmp; + for (double k=-1;k<=1;k+=0.05) { // de 0 à 2 pi + int px=x+(int)Math.round(radius*Math.cos(k*pi)); //px = pos x du contour du supposé cercle + int py=y+(int)Math.round(radius*Math.sin(k*pi)); //diam calculé +/- 42 pixels + if(py<0)py=0; + if(py>img.getHeight())py=img.getHeight()-1; + if(px<0)px=0; + if (px>img.getWidth())px=img.getWidth()-1; + tmp=new Color(img.getRGB(px, py)); + if (tmp.getGreen()>20) { //si pixel == blanc + return false; + } + } + return true; + } + + + public double getAngle(int[][] tab) { + double[] res= new double[4];int resi=0; + int cmpt=0; + int angle=0; + for (int i=0;i90/2) + retour=180-90-retour; + + if((xa