diff --git a/TutoOpenCv/.DS_Store b/TutoOpenCv/.DS_Store index 3fcccba..33bce5b 100644 Binary files a/TutoOpenCv/.DS_Store and b/TutoOpenCv/.DS_Store differ diff --git a/TutoOpenCv/bin/AnalyseVideo.class b/TutoOpenCv/bin/AnalyseVideo.class index 794a8f7..791d576 100644 Binary files a/TutoOpenCv/bin/AnalyseVideo.class and b/TutoOpenCv/bin/AnalyseVideo.class differ diff --git a/TutoOpenCv/bin/Fonctions.class b/TutoOpenCv/bin/Fonctions.class index 9034143..21d0d7b 100644 Binary files a/TutoOpenCv/bin/Fonctions.class and b/TutoOpenCv/bin/Fonctions.class differ diff --git a/TutoOpenCv/bin/MaBibliothequeTraitementImage.class b/TutoOpenCv/bin/MaBibliothequeTraitementImage.class index bfbb9aa..7f83056 100644 Binary files a/TutoOpenCv/bin/MaBibliothequeTraitementImage.class and b/TutoOpenCv/bin/MaBibliothequeTraitementImage.class differ diff --git a/TutoOpenCv/bin/MaBibliothequeTraitementImageEtendue_DEUX.class b/TutoOpenCv/bin/MaBibliothequeTraitementImageEtendue_DEUX.class deleted file mode 100644 index 0c6439d..0000000 Binary files a/TutoOpenCv/bin/MaBibliothequeTraitementImageEtendue_DEUX.class and /dev/null differ diff --git a/TutoOpenCv/bin/Principale.class b/TutoOpenCv/bin/Principale.class index 084e8de..1d920d8 100644 Binary files a/TutoOpenCv/bin/Principale.class and b/TutoOpenCv/bin/Principale.class differ diff --git a/TutoOpenCv/bin/Principale_DEUX.class b/TutoOpenCv/bin/Principale_DEUX.class deleted file mode 100644 index 8cd6263..0000000 Binary files a/TutoOpenCv/bin/Principale_DEUX.class and /dev/null differ diff --git a/TutoOpenCv/bin/TestFunc.class b/TutoOpenCv/bin/TestFunc.class index 74cd977..2839b86 100644 Binary files a/TutoOpenCv/bin/TestFunc.class and b/TutoOpenCv/bin/TestFunc.class differ diff --git a/TutoOpenCv/src/AnalyseVideo.java b/TutoOpenCv/src/AnalyseVideo.java index b61f832..b99e165 100644 --- a/TutoOpenCv/src/AnalyseVideo.java +++ b/TutoOpenCv/src/AnalyseVideo.java @@ -39,52 +39,36 @@ public static void main(String[] args) { jframe.setVisible(true); Mat frame = new Mat(); - VideoCapture camera = new VideoCapture("/Users/ibrahim/Java_Project/TutoOpenCv/assets/video1.mp4"); - Mat PanneauAAnalyser = null; - - while (camera.read(frame)) { - // completer - //transformation hsv - Mat imageTransformee=MaBibliothequeTraitementImage.transformeBGRversHSV(frame); - // saturation des rouges - Mat imageSaturee=MaBibliothequeTraitementImage.seuillage(imageTransformee, 6, 170, 110); - //liste de contours - List ListeContours= MaBibliothequeTraitementImage.ExtractContours(imageSaturee); - int i=0; - //je test si y'a des contours + VideoCapture camera = new VideoCapture("/Users/ibrahim/Java_Project/TutoOpenCv/assets/video2.mp4"); + Mat objetrond = null; + + while (camera.read(frame)) { + // completer + Mat transformee=MaBibliothequeTraitementImage.transformeBGRversHSV(frame); + Mat saturee=MaBibliothequeTraitementImage.seuillage(transformee, 6, 170, 110); + //Imgproc.GaussianBlur(frame, objetrond, null, 0, 0, 0); + List ListeContours= MaBibliothequeTraitementImage.ExtractContours(saturee); + for (MatOfPoint contour: ListeContours ){ - i++; - PanneauAAnalyser=MaBibliothequeTraitementImage.DetectForm(imageSaturee,contour); - - if (identifiepanneau(PanneauAAnalyser)==0){ - System.out.println("Panneau 30 d�t�ct�"); - } - else if (identifiepanneau(PanneauAAnalyser)==1){ - System.out.println("Panneau 50 d�t�ct�"); - } - else if (identifiepanneau(PanneauAAnalyser)==2){ - System.out.println("Panneau 70 d�t�ct�"); - } - else if (identifiepanneau(PanneauAAnalyser)==3){ - System.out.println("Panneau 90 d�t�ct�"); + + objetrond=MaBibliothequeTraitementImage.DetectForm(frame,contour); + if (objetrond!=null){ + MaBibliothequeTraitementImage.afficheImage("Objet rond", objetrond); + identifiepanneau(objetrond); } - else if (identifiepanneau(PanneauAAnalyser)==4){ - System.out.println("Panneau 110 d�t�ct�"); - } - else if (identifiepanneau(PanneauAAnalyser)==5){ - System.out.println("Panneau interdiction depassement"); - } - else{ - System.out.println("Aucun panneau"); - } + + } - //J'affiche le panneau de reference et la phrase + + + ImageIcon image = new ImageIcon(Mat2bufferedImage(frame)); vidpanel.setIcon(image); vidpanel.repaint(); } } + @@ -122,9 +106,11 @@ public static int identifiepanneau(Mat objetrond){ double scoremax=scores[0]; for(int j=1;jscoremax){scoremax=scores[j];indexmax=j;}} - - + if (scores[j]>scoremax){ + scoremax=scores[j]; + indexmax=j; + } + } } return indexmax; } diff --git a/TutoOpenCv/src/Fonctions.java b/TutoOpenCv/src/Fonctions.java index f7b2b63..baef18b 100644 --- a/TutoOpenCv/src/Fonctions.java +++ b/TutoOpenCv/src/Fonctions.java @@ -112,4 +112,100 @@ public static ArrayList detect_panneau_image(String fichier){ return res; } + + public static ArrayList detect_panneau_imagebis(Mat fichier){ + System.loadLibrary(Core.NATIVE_LIBRARY_NAME); + ArrayList res = new ArrayList(); + Mat imageOriginale=Highgui.imread("/Users/ibrahim/Java_Project/TutoOpenCv/assets/Temoin.png",Highgui.CV_LOAD_IMAGE_COLOR); + Mat imageTransformee=MaBibliothequeTraitementImage.transformeBGRversHSV(imageOriginale); + Mat imageSaturee=MaBibliothequeTraitementImage.seuillage(imageTransformee, 6, 170, 110); + + + //Ouverture le l'image et saturation des rouges + Mat m=Highgui.imshow(fichier,Highgui.CV_LOAD_IMAGE_COLOR); + MaBibliothequeTraitementImage.afficheImage("Image test�e", m); + Mat transformee=MaBibliothequeTraitementImage.transformeBGRversHSV(m); + + //la methode seuillage est ici extraite de l'archivage jar du meme nom + Mat saturee=MaBibliothequeTraitementImage.seuillage(transformee, 6, 170, 110); + Mat objetrond = null; + + //Cr�ation d'une liste des contours � partir de l'image satur�e + List ListeContours= MaBibliothequeTraitementImage.ExtractContours(saturee); + int i=0; + double [] scores=new double [6]; + //Pour tous les contours de la liste + for (MatOfPoint contour: ListeContours ){ + i++; + objetrond=MaBibliothequeTraitementImage.DetectForm(m,contour); + + if (objetrond!=null){ + MaBibliothequeTraitementImage.afficheImage("Objet rond det�ct�", objetrond); + scores[0]=MaBibliothequeTraitementImage.tauxDeSimilitude(objetrond,"/Users/ibrahim/Java_Project/TutoOpenCv/assets/ref30.jpg"); + scores[1]=MaBibliothequeTraitementImage.tauxDeSimilitude(objetrond,"/Users/ibrahim/Java_Project/TutoOpenCv/assets/ref50.jpg"); + scores[2]=MaBibliothequeTraitementImage.tauxDeSimilitude(objetrond,"/Users/ibrahim/Java_Project/TutoOpenCv/assets/ref70.jpg"); + scores[3]=MaBibliothequeTraitementImage.tauxDeSimilitude(objetrond,"/Users/ibrahim/Java_Project/TutoOpenCv/assets/ref90.jpg"); + scores[4]=MaBibliothequeTraitementImage.tauxDeSimilitude(objetrond,"/Users/ibrahim/Java_Project/TutoOpenCv/assets/ref110.jpg"); + scores[5]=MaBibliothequeTraitementImage.tauxDeSimilitude(objetrond,"/Users/ibrahim/Java_Project/TutoOpenCv/assets/refdouble.jpg"); + //recherche de l'index du maximum et affichage du panneau detect� + double scoremax=-1; + int indexmax=0; + for(int j=0;jscoremax){ + scoremax=scores[j]; + indexmax=j; + } + } + if(scoremax<0){System.out.println("Aucun Panneau d�t�ct�");} + else{switch(indexmax){ + case -1:;break; + case 0:System.out.println("Panneau 30 d�t�ct�"); + res.add(Highgui.imread("/Users/ibrahim/Java_Project/TutoOpenCv/assets/ref30.jpg")); + break; + case 1:System.out.println("Panneau 50 d�t�ct�"); + res.add(Highgui.imread("/Users/ibrahim/Java_Project/TutoOpenCv/assets/ref50.jpg")); + break; + case 2:System.out.println("Panneau 70 d�t�ct�"); + res.add(Highgui.imread("/Users/ibrahim/Java_Project/TutoOpenCv/asets/ref70.jpg")); + break; + case 3:System.out.println("Panneau 90 d�t�ct�"); + res.add(Highgui.imread("/Users/ibrahim/Java_Project/TutoOpenCv/assets/ref90.jpg")); + break; + case 4:System.out.println("Panneau 110 d�t�ct�"); + res.add(Highgui.imread("/Users/ibrahim/Java_Project/TutoOpenCv/assets/ref110.jpg")); + break; + case 5:System.out.println("Panneau interdiction de d�passer d�t�ct�"); + res.add(Highgui.imread("/Users/ibrahim/Java_Project/TutoOpenCv/assets/refdouble.jpg")); + break; + }} + + } + } + return res; + + } + public static ArrayList detect_panneau_video(String fichier){ + ArrayList res = new ArrayList(); + + return res; + + } + public static void afficheImage(Mat img){ + MatOfByte matOfByte = new MatOfByte(); + Highgui.imencode(".png", img, matOfByte); + byte[] byteArray = matOfByte.toArray(); + java.awt.image.BufferedImage bufImage = null; + try { + InputStream in = new ByteArrayInputStream(byteArray); + bufImage = ImageIO.read(in); + JFrame frame = new JFrame(); + frame.getContentPane().add(new JLabel(new ImageIcon(bufImage))); + frame.pack(); + frame.setVisible(true); + } + catch (Exception e){ + e.printStackTrace(); + } + } + } diff --git a/TutoOpenCv/src/MaBibliothequeTraitementImage.java b/TutoOpenCv/src/MaBibliothequeTraitementImage.java index 21d8f7f..bebcf2a 100644 --- a/TutoOpenCv/src/MaBibliothequeTraitementImage.java +++ b/TutoOpenCv/src/MaBibliothequeTraitementImage.java @@ -84,10 +84,11 @@ public static Mat seuillage(Mat input, int seuilRougeOrange, int seuilRougeViole Mat threshold_img2 = new Mat(); //threshold_img1 = seuillage_exemple(input, seuilRougeViolet); //threshold_img1 = seuillage_exemple(input, seuilRougeOrange); - Core.inRange(input,new Scalar(0,seuilSaturation,100),new Scalar(seuilRougeOrange,255,255),threshold_img1); - Core.inRange(input,new Scalar(160,seuilSaturation,100),new Scalar(seuilRougeViolet,255,255),threshold_img2); + Core.inRange(input,new Scalar(0,seuilSaturation,0),new Scalar(seuilRougeOrange,255,255),threshold_img1); + Core.inRange(input,new Scalar(160,seuilSaturation,0),new Scalar(seuilRougeViolet,255,255),threshold_img2); Core.bitwise_or(threshold_img1,threshold_img2, threshold_img); - Imgproc.GaussianBlur(threshold_img,threshold_img,new Size(9,9),2,2); + Imgproc.GaussianBlur(threshold_img,threshold_img,new Size(threshold_img.rows(),threshold_img.cols()),9,9); + //image satur�e � retourner return threshold_img; @@ -96,7 +97,6 @@ public static Mat seuillage(Mat input, int seuilRougeOrange, int seuilRougeViole } - //Methode d'exemple qui permet de saturer les couleurs rouges � partir d'un seul seuil public static Mat seuillage_exemple(Mat input, int seuilRougeViolet){ // Decomposition en 3 cannaux HSV @@ -111,7 +111,7 @@ public static Mat seuillage_exemple(Mat input, int seuilRougeViolet){ return rouges; } - //Methode qui permet d'extraire les contours d'une image donnee + //Methode qui permet d'extraire les contours d'une image donnee public static List ExtractContours(Mat input) { // Detecter les contours des formes trouv�es int thresh = 100; @@ -208,8 +208,6 @@ public static Mat DetectForm(Mat img,MatOfPoint contour) { } - - public static double angle(Point a, Point b, Point c) { Point ab = new Point( b.x - a.x, b.y - a.y ); Point cb = new Point( b.x - c.x, b.y - c.y ); @@ -219,7 +217,6 @@ public static double angle(Point a, Point b, Point c) { return Math.floor(alpha * 180. / Math.PI + 0.5); } - //methode � completer public static double tauxDeSimilitude(Mat object,String signfile) { @@ -260,13 +257,5 @@ public static double tauxDeSimilitude(Mat object,String signfile) { } - - - - - - - - } diff --git a/TutoOpenCv/src/Principale.java b/TutoOpenCv/src/Principale.java index 9c27be3..87496c1 100644 --- a/TutoOpenCv/src/Principale.java +++ b/TutoOpenCv/src/Principale.java @@ -5,6 +5,7 @@ import org.opencv.core.*; import org.opencv.highgui.*; import utilitaireAgreg.MaBibliothequeTraitementImage; + public class Principale { public static void main(String[] args) @@ -22,7 +23,7 @@ public static void main(String[] args) MaBibliothequeTraitementImage.afficheImage("Saturation des rouges", imageSaturee); //Ouverture le l'image et saturation des rouges - Mat m=Highgui.imread("/Users/ibrahim/Java_Project/TutoOpenCv/assets/p10.jpg",Highgui.CV_LOAD_IMAGE_COLOR); + Mat m=Highgui.imread("/Users/ibrahim/Java_Project/TutoOpenCv/assets/p7.jpg",Highgui.CV_LOAD_IMAGE_COLOR); MaBibliothequeTraitementImage.afficheImage("Image test�e", m); Mat transformee=MaBibliothequeTraitementImage.transformeBGRversHSV(m); //la methode seuillage est ici extraite de l'archivage jar du meme nom @@ -82,10 +83,7 @@ public static void main(String[] args) res.add(Highgui.imread("/Users/ibrahim/Java_Project/TutoOpenCv/assets/refdouble.jpg")); break; }} - } } - - } } \ No newline at end of file diff --git a/TutoOpenCv/src/TestFunc.java b/TutoOpenCv/src/TestFunc.java index ee8a8d9..b9e468d 100644 --- a/TutoOpenCv/src/TestFunc.java +++ b/TutoOpenCv/src/TestFunc.java @@ -41,6 +41,7 @@ public class TestFunc{ public static void main(String[] args){ Fonctions.detect_panneau_image("/Users/ibrahim/Java_Project/TutoOpenCv/assets/p10.jpg"); + Fonctions.detect_panneau_video("/Users/ibrahim/Java_Project/TutoOpenCv/assets/video2.mp4"); }