diff --git a/.DS_Store b/.DS_Store index 1647e72..20a5810 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git "a/Deuxi\303\244meEtude/.classpath" "b/Deuxi\303\244meEtude/.classpath" deleted file mode 100644 index 4759107..0000000 --- "a/Deuxi\303\244meEtude/.classpath" +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git "a/Deuxi\303\244meEtude/.project" "b/Deuxi\303\244meEtude/.project" deleted file mode 100644 index f1dd6bf..0000000 --- "a/Deuxi\303\244meEtude/.project" +++ /dev/null @@ -1,28 +0,0 @@ - - - DeuxièmeEtude - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - - - 1683024125971 - - 30 - - org.eclipse.core.resources.regexFilterMatcher - node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ - - - - diff --git "a/Deuxi\303\244meEtude/.settings/org.eclipse.jdt.core.prefs" "b/Deuxi\303\244meEtude/.settings/org.eclipse.jdt.core.prefs" deleted file mode 100644 index bb35fa0..0000000 --- "a/Deuxi\303\244meEtude/.settings/org.eclipse.jdt.core.prefs" +++ /dev/null @@ -1,11 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.8 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.8 diff --git "a/Deuxi\303\244meEtude/Mabiblio.jar" "b/Deuxi\303\244meEtude/Mabiblio.jar" deleted file mode 100644 index 5b6929c..0000000 Binary files "a/Deuxi\303\244meEtude/Mabiblio.jar" and /dev/null differ diff --git "a/Deuxi\303\244meEtude/Thumbs.db" "b/Deuxi\303\244meEtude/Thumbs.db" deleted file mode 100644 index 90e6818..0000000 Binary files "a/Deuxi\303\244meEtude/Thumbs.db" and /dev/null differ diff --git "a/Deuxi\303\244meEtude/bin/.DS_Store" "b/Deuxi\303\244meEtude/bin/.DS_Store" deleted file mode 100644 index f0a562a..0000000 Binary files "a/Deuxi\303\244meEtude/bin/.DS_Store" and /dev/null differ diff --git "a/Deuxi\303\244meEtude/bin/MaBibliothequeTraitementImageEtendue_DEUX.class" "b/Deuxi\303\244meEtude/bin/MaBibliothequeTraitementImageEtendue_DEUX.class" deleted file mode 100644 index 0c6439d..0000000 Binary files "a/Deuxi\303\244meEtude/bin/MaBibliothequeTraitementImageEtendue_DEUX.class" and /dev/null differ diff --git "a/Deuxi\303\244meEtude/bin/Principale_DEUX.class" "b/Deuxi\303\244meEtude/bin/Principale_DEUX.class" deleted file mode 100644 index 8cd6263..0000000 Binary files "a/Deuxi\303\244meEtude/bin/Principale_DEUX.class" and /dev/null differ diff --git "a/Deuxi\303\244meEtude/p1.jpg" "b/Deuxi\303\244meEtude/p1.jpg" deleted file mode 100644 index 222e3ae..0000000 Binary files "a/Deuxi\303\244meEtude/p1.jpg" and /dev/null differ diff --git "a/Deuxi\303\244meEtude/p10.jpg" "b/Deuxi\303\244meEtude/p10.jpg" deleted file mode 100644 index 4a21be3..0000000 Binary files "a/Deuxi\303\244meEtude/p10.jpg" and /dev/null differ diff --git "a/Deuxi\303\244meEtude/p2.jpg" "b/Deuxi\303\244meEtude/p2.jpg" deleted file mode 100644 index ca33c65..0000000 Binary files "a/Deuxi\303\244meEtude/p2.jpg" and /dev/null differ diff --git "a/Deuxi\303\244meEtude/p3.jpg" "b/Deuxi\303\244meEtude/p3.jpg" deleted file mode 100644 index eb34287..0000000 Binary files "a/Deuxi\303\244meEtude/p3.jpg" and /dev/null differ diff --git "a/Deuxi\303\244meEtude/p4.jpg" "b/Deuxi\303\244meEtude/p4.jpg" deleted file mode 100644 index e5c2fba..0000000 Binary files "a/Deuxi\303\244meEtude/p4.jpg" and /dev/null differ diff --git "a/Deuxi\303\244meEtude/p5.jpg" "b/Deuxi\303\244meEtude/p5.jpg" deleted file mode 100644 index e443c8f..0000000 Binary files "a/Deuxi\303\244meEtude/p5.jpg" and /dev/null differ diff --git "a/Deuxi\303\244meEtude/p6.jpg" "b/Deuxi\303\244meEtude/p6.jpg" deleted file mode 100644 index cd6b4e9..0000000 Binary files "a/Deuxi\303\244meEtude/p6.jpg" and /dev/null differ diff --git "a/Deuxi\303\244meEtude/p7.JPG" "b/Deuxi\303\244meEtude/p7.JPG" deleted file mode 100644 index 827c466..0000000 Binary files "a/Deuxi\303\244meEtude/p7.JPG" and /dev/null differ diff --git "a/Deuxi\303\244meEtude/p8.jpg" "b/Deuxi\303\244meEtude/p8.jpg" deleted file mode 100644 index 86f84a8..0000000 Binary files "a/Deuxi\303\244meEtude/p8.jpg" and /dev/null differ diff --git "a/Deuxi\303\244meEtude/p9.jpg" "b/Deuxi\303\244meEtude/p9.jpg" deleted file mode 100644 index fb9b846..0000000 Binary files "a/Deuxi\303\244meEtude/p9.jpg" and /dev/null differ diff --git "a/Deuxi\303\244meEtude/ref110.jpg" "b/Deuxi\303\244meEtude/ref110.jpg" deleted file mode 100644 index 2aad348..0000000 Binary files "a/Deuxi\303\244meEtude/ref110.jpg" and /dev/null differ diff --git "a/Deuxi\303\244meEtude/ref30.jpg" "b/Deuxi\303\244meEtude/ref30.jpg" deleted file mode 100644 index 32627e4..0000000 Binary files "a/Deuxi\303\244meEtude/ref30.jpg" and /dev/null differ diff --git "a/Deuxi\303\244meEtude/ref50.jpg" "b/Deuxi\303\244meEtude/ref50.jpg" deleted file mode 100644 index 0ddc9ac..0000000 Binary files "a/Deuxi\303\244meEtude/ref50.jpg" and /dev/null differ diff --git "a/Deuxi\303\244meEtude/ref70.jpg" "b/Deuxi\303\244meEtude/ref70.jpg" deleted file mode 100644 index 3298076..0000000 Binary files "a/Deuxi\303\244meEtude/ref70.jpg" and /dev/null differ diff --git "a/Deuxi\303\244meEtude/ref90.jpg" "b/Deuxi\303\244meEtude/ref90.jpg" deleted file mode 100644 index 34aa798..0000000 Binary files "a/Deuxi\303\244meEtude/ref90.jpg" and /dev/null differ diff --git "a/Deuxi\303\244meEtude/refdouble.jpg" "b/Deuxi\303\244meEtude/refdouble.jpg" deleted file mode 100644 index 5c057d3..0000000 Binary files "a/Deuxi\303\244meEtude/refdouble.jpg" and /dev/null differ diff --git "a/Deuxi\303\244meEtude/src/.DS_Store" "b/Deuxi\303\244meEtude/src/.DS_Store" deleted file mode 100644 index c5f9c5f..0000000 Binary files "a/Deuxi\303\244meEtude/src/.DS_Store" and /dev/null differ diff --git "a/Deuxi\303\244meEtude/src/MaBibliothequeTraitementImageEtendueDEUX.java" "b/Deuxi\303\244meEtude/src/MaBibliothequeTraitementImageEtendueDEUX.java" deleted file mode 100644 index 4169276..0000000 --- "a/Deuxi\303\244meEtude/src/MaBibliothequeTraitementImageEtendueDEUX.java" +++ /dev/null @@ -1,225 +0,0 @@ -import java.awt.Dimension; -import java.awt.image.BufferedImage; -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Random; -import java.util.Vector; - -import javax.imageio.ImageIO; -import javax.swing.ImageIcon; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JPanel; - -import org.opencv.core.Core; -import org.opencv.core.CvType; -import org.opencv.core.Mat; -import org.opencv.core.MatOfByte; -import org.opencv.core.MatOfDMatch; -import org.opencv.core.MatOfInt4; -import org.opencv.core.MatOfKeyPoint; -import org.opencv.core.MatOfPoint; -import org.opencv.core.MatOfPoint2f; -import org.opencv.core.Point; -import org.opencv.core.Rect; -import org.opencv.core.Scalar; -import org.opencv.core.Size; -import org.opencv.features2d.DMatch; -import org.opencv.features2d.DescriptorExtractor; -import org.opencv.features2d.DescriptorMatcher; -import org.opencv.features2d.FeatureDetector; -import org.opencv.features2d.Features2d; -import org.opencv.highgui.Highgui; -import org.opencv.imgproc.Imgproc; - -public class MaBibliothequeTraitementImageEtendue { - //Contient toutes les méthodes necessaires à la transformation des images - - - //Methode qui permet de transformer une matrice intialement au format BGR au format HSV - public static Mat transformeBGRversHSV(Mat matriceBGR){ - Mat matriceHSV=new Mat(matriceBGR.height(),matriceBGR.cols(),matriceBGR.type()); - Imgproc.cvtColor(matriceBGR,matriceHSV,Imgproc.COLOR_BGR2HSV); - return matriceHSV; - - } - - //Methode qui convertit une matrice avec 3 canaux en un vecteur de 3 matrices monocanal (un canal par couleur) - public static Vector splitHSVChannels(Mat input) { - Vector channels = new Vector(); - Core.split(input, channels); - return channels; - } - - //Methode qui permet d'afficher une image sur un panel - public static void afficheImage(String title, Mat img){ - MatOfByte matOfByte=new MatOfByte(); - Highgui.imencode(".png",img,matOfByte); - byte[] byteArray=matOfByte.toArray(); - BufferedImage bufImage=null; - try{ - InputStream in=new ByteArrayInputStream(byteArray); - bufImage=ImageIO.read(in); - JFrame frame=new JFrame(); - frame.setTitle(title); - frame.getContentPane().add(new JLabel(new ImageIcon(bufImage))); - frame.pack(); - frame.setVisible(true); - - } - catch(Exception e){ - e.printStackTrace(); - } - - - } - - - - //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; - Mat canny_output = new Mat(); - List contours = new ArrayList(); - MatOfInt4 hierarchy = new MatOfInt4(); - Imgproc.Canny( input, canny_output, thresh, thresh*2); - - - /// Find extreme outer contours - Imgproc.findContours( canny_output, contours, hierarchy,Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE); - - Mat drawing = Mat.zeros( canny_output.size(), CvType.CV_8UC3 ); - Random rand = new Random(); - for( int i = 0; i< contours.size(); i++ ) - { - Scalar color = new Scalar( rand.nextInt(255 - 0 + 1) , rand.nextInt(255 - 0 + 1),rand.nextInt(255 - 0 + 1) ); - Imgproc.drawContours( drawing, contours, i, color, 1, 8, hierarchy, 0, new Point() ); - } - //afficheImage("Contours",drawing); - - return contours; - } - - //Methode qui permet de decouper et identifier les contours carrés, triangulaires ou rectangulaires. - //Renvoie null si aucun contour rond n'a été trouvé. - //Renvoie une matrice carrée englobant un contour rond si un contour rond a été trouvé - public static Mat DetectForm(Mat img,MatOfPoint contour) { - MatOfPoint2f matOfPoint2f = new MatOfPoint2f(); - MatOfPoint2f approxCurve = new MatOfPoint2f(); - float[] radius = new float[1]; - Point center = new Point(); - Rect rect = Imgproc.boundingRect(contour); - double contourArea = Imgproc.contourArea(contour); - - - matOfPoint2f.fromList(contour.toList()); - // Cherche le plus petit cercle entourant le contour - Imgproc.minEnclosingCircle(matOfPoint2f, center, radius); - //System.out.println(contourArea+" "+Math.PI*radius[0]*radius[0]); - //on dit que c'est un cercle si l'aire occupé par le contour est à supérieure à 80% de l'aire occupée par un cercle parfait - if ((contourArea / (Math.PI*radius[0]*radius[0])) >=0.8) { - //System.out.println("Cercle"); - Core.circle(img, center, (int)radius[0], new Scalar(255, 0, 0), 2); - Core.rectangle(img, new Point(rect.x,rect.y), new Point(rect.x+rect.width,rect.y+rect.height), new Scalar (0, 255, 0), 2); - Mat tmp = img.submat(rect.y,rect.y+rect.height,rect.x,rect.x+rect.width); - Mat sign = Mat.zeros(tmp.size(),tmp.type()); - tmp.copyTo(sign); - return sign; - }else { - - Imgproc.approxPolyDP(matOfPoint2f, approxCurve, Imgproc.arcLength(matOfPoint2f, true) * 0.02, true); - long total = approxCurve.total(); - if (total == 3 ) { // is triangle - //System.out.println("Triangle"); - Point [] pt = approxCurve.toArray(); - Core.line(img, pt[0], pt[1], new Scalar(255,0,0),2); - Core.line(img, pt[1], pt[2], new Scalar(255,0,0),2); - Core.line(img, pt[2], pt[0], new Scalar(255,0,0),2); - Core.rectangle(img, new Point(rect.x,rect.y), new Point(rect.x+rect.width,rect.y+rect.height), new Scalar (0, 255, 0), 2); - Mat tmp = img.submat(rect.y,rect.y+rect.height,rect.x,rect.x+rect.width); - Mat sign = Mat.zeros(tmp.size(),tmp.type()); - tmp.copyTo(sign); - return null; - } - if (total >= 4 && total <= 6) { - List cos = new ArrayList<>(); - Point[] points = approxCurve.toArray(); - for (int j = 2; j < total + 1; j++) { - cos.add(angle(points[(int) (j % total)], points[j - 2], points[j - 1])); - } - Collections.sort(cos); - Double minCos = cos.get(0); - Double maxCos = cos.get(cos.size() - 1); - boolean isRect = total == 4 && minCos >= -0.1 && maxCos <= 0.3; - boolean isPolygon = (total == 5 && minCos >= -0.34 && maxCos <= -0.27) || (total == 6 && minCos >= -0.55 && maxCos <= -0.45); - if (isRect) { - double ratio = Math.abs(1 - (double) rect.width / rect.height); - //drawText(rect.tl(), ratio <= 0.02 ? "SQU" : "RECT"); - //System.out.println("Rectangle"); - Core.rectangle(img, new Point(rect.x,rect.y), new Point(rect.x+rect.width,rect.y+rect.height), new Scalar (0, 255, 0), 2); - Mat tmp = img.submat(rect.y,rect.y+rect.height,rect.x,rect.x+rect.width); - Mat sign = Mat.zeros(tmp.size(),tmp.type()); - tmp.copyTo(sign); - return null; - } - if (isPolygon) { - //System.out.println("Polygon"); - //drawText(rect.tl(), "Polygon"); - } - } - } - return null; - - } - - - - 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 ); - double dot = (ab.x * cb.x + ab.y * cb.y); // dot product - double cross = (ab.x * cb.y - ab.y * cb.x); // cross product - double alpha = Math.atan2(cross, dot); - return Math.floor(alpha * 180. / Math.PI + 0.5); - } - - - //methode à completer - public static double Similitude(Mat object,String signfile) { - - // Conversion du signe de reference en niveaux de gris et normalisation - Mat panneauref = Highgui.imread(signfile); - Mat graySign = new Mat(panneauref.rows(), panneauref.cols(), panneauref.type()); - Imgproc.cvtColor(panneauref, graySign, Imgproc.COLOR_BGRA2GRAY); - Core.normalize(graySign, graySign, 0, 255, Core.NORM_MINMAX); - Mat signeNoirEtBlanc=new Mat(); - - - - //Conversion du panneau extrait de l'image en gris et normalisation et redimensionnement à la taille du panneau de réference - Mat grayObject = new Mat(panneauref.rows(), panneauref.cols(), panneauref.type()); - Imgproc.resize(object, object, graySign.size()); - //afficheImage("Panneau extrait de l'image",object); - Imgproc.cvtColor(object, grayObject, Imgproc.COLOR_BGRA2GRAY); - Core.normalize(grayObject, grayObject, 0, 255, Core.NORM_MINMAX); - //Imgproc.resize(grayObject, grayObject, graySign.size()); - - - - //à compléter... - - return -1; - - - - - } - -} - diff --git "a/Deuxi\303\244meEtude/src/PrincipaleDEUX.java" "b/Deuxi\303\244meEtude/src/PrincipaleDEUX.java" deleted file mode 100644 index acbd3c3..0000000 --- "a/Deuxi\303\244meEtude/src/PrincipaleDEUX.java" +++ /dev/null @@ -1,61 +0,0 @@ - -import java.util.Arrays; -import java.util.List; - -import org.opencv.core.*; -import org.opencv.highgui.*; -import utilitaireAgreg.MaBibliothequeTraitementImage; -public class Principale { - - public static void main(String[] args) - { - //Ouverture le l'image et saturation des rouges - System.loadLibrary("opencv_java249"); - Mat m=Highgui.imread("p10.jpg",Highgui.CV_LOAD_IMAGE_COLOR); - MaBibliothequeTraitementImageEtendue.afficheImage("Image test�e", m); - Mat transformee=MaBibliothequeTraitementImageEtendue.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= MaBibliothequeTraitementImageEtendue .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.Similitude(objetrond,"ref30.jpg"); - scores[1]=MaBibliothequeTraitementImage.Similitude(objetrond,"ref50.jpg"); - scores[2]=MaBibliothequeTraitementImage.Similitude(objetrond,"ref70.jpg"); - scores[3]=MaBibliothequeTraitementImage.Similitude(objetrond,"ref90.jpg"); - scores[4]=MaBibliothequeTraitementImage.Similitude(objetrond,"ref110.jpg"); - scores[5]=MaBibliothequeTraitementImage.Similitude(objetrond,"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�");break; - case 1:System.out.println("Panneau 50 d�t�ct�");break; - case 2:System.out.println("Panneau 70 d�t�ct�");break; - case 3:System.out.println("Panneau 90 d�t�ct�");break; - case 4:System.out.println("Panneau 110 d�t�ct�");break; - case 5:System.out.println("Panneau interdiction de d�passer d�t�ct�");break; - }} - - } - } - - - } -} \ No newline at end of file diff --git "a/Deuxi\303\244meEtude/.DS_Store" b/TroisiemeEtude/.DS_Store similarity index 80% rename from "Deuxi\303\244meEtude/.DS_Store" rename to TroisiemeEtude/.DS_Store index 0fac40f..f7d3a76 100644 Binary files "a/Deuxi\303\244meEtude/.DS_Store" and b/TroisiemeEtude/.DS_Store differ diff --git a/TutoOpenCv/.vscode/launch.json b/TutoOpenCv/.vscode/launch.json index 26ef7ab..3c980af 100644 --- a/TutoOpenCv/.vscode/launch.json +++ b/TutoOpenCv/.vscode/launch.json @@ -4,6 +4,22 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + { + "type": "java", + "name": "TestFunc", + "request": "launch", + "mainClass": "TestFunc", + "projectName": "TutoOpenCv_56708bcb", + "vmArgs": "-Djava.library.path=/Users/Ibrahim/Tools/opencv-2.4.13.6/build/lib" + }, + { + "type": "java", + "name": "AnalyseVideo", + "request": "launch", + "mainClass": "AnalyseVideo", + "projectName": "TutoOpenCv_56708bcb", + "vmArgs": "-Djava.library.path=/Users/Ibrahim/Tools/opencv-2.4.13.6/build/lib" + }, { "type": "java", "name": "BGRtoHSV", diff --git a/TutoOpenCv/assets/video1.avi b/TutoOpenCv/assets/video1.avi new file mode 100644 index 0000000..8fac3e1 Binary files /dev/null and b/TutoOpenCv/assets/video1.avi differ diff --git a/TutoOpenCv/assets/video1.mp4 b/TutoOpenCv/assets/video1.mp4 new file mode 100644 index 0000000..3826b37 Binary files /dev/null and b/TutoOpenCv/assets/video1.mp4 differ diff --git a/TutoOpenCv/assets/video2.avi b/TutoOpenCv/assets/video2.avi new file mode 100644 index 0000000..52209c9 Binary files /dev/null and b/TutoOpenCv/assets/video2.avi differ diff --git a/TutoOpenCv/assets/video2.mp4 b/TutoOpenCv/assets/video2.mp4 new file mode 100644 index 0000000..9ecf0e7 Binary files /dev/null and b/TutoOpenCv/assets/video2.mp4 differ diff --git a/TutoOpenCv/bin/AnalyseVideo.class b/TutoOpenCv/bin/AnalyseVideo.class new file mode 100644 index 0000000..794a8f7 Binary files /dev/null and b/TutoOpenCv/bin/AnalyseVideo.class differ diff --git a/TutoOpenCv/bin/Fonctions.class b/TutoOpenCv/bin/Fonctions.class new file mode 100644 index 0000000..9034143 Binary files /dev/null and b/TutoOpenCv/bin/Fonctions.class differ diff --git a/TutoOpenCv/bin/Principale.class b/TutoOpenCv/bin/Principale.class index 05be207..084e8de 100644 Binary files a/TutoOpenCv/bin/Principale.class and b/TutoOpenCv/bin/Principale.class differ diff --git a/TutoOpenCv/bin/TestFunc.class b/TutoOpenCv/bin/TestFunc.class new file mode 100644 index 0000000..74cd977 Binary files /dev/null and b/TutoOpenCv/bin/TestFunc.class differ diff --git a/TutoOpenCv/src/AnalyseVideo.java b/TutoOpenCv/src/AnalyseVideo.java new file mode 100644 index 0000000..b61f832 --- /dev/null +++ b/TutoOpenCv/src/AnalyseVideo.java @@ -0,0 +1,133 @@ +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import javax.imageio.ImageIO; +import javax.swing.ImageIcon; +import javax.swing.JFrame; +import javax.swing.JLabel; + +import org.opencv.core.Core; +import org.opencv.core.CvType; +import org.opencv.core.Mat; +import org.opencv.core.MatOfByte; +import org.opencv.core.MatOfPoint; +import org.opencv.core.Rect; +import org.opencv.core.Scalar; +import org.opencv.core.Size; +import org.opencv.highgui.Highgui; +import org.opencv.highgui.VideoCapture; +import org.opencv.imgproc.Imgproc; +import utilitaireAgreg.*; +public class AnalyseVideo { + static { + System.loadLibrary(Core.NATIVE_LIBRARY_NAME); + } + + static Mat imag = null; + + public static void main(String[] args) { + JFrame jframe = new JFrame("Detection de panneaux sur un flux vid�o"); + jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + JLabel vidpanel = new JLabel(); + jframe.setContentPane(vidpanel); + jframe.setSize(720, 480); + 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 + 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�"); + } + 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(); + } + } + + + + + + + public static BufferedImage Mat2bufferedImage(Mat image) { + MatOfByte bytemat = new MatOfByte(); + Highgui.imencode(".jpg", image, bytemat); + byte[] bytes = bytemat.toArray(); + InputStream in = new ByteArrayInputStream(bytes); + BufferedImage img = null; + try { + img = ImageIO.read(in); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return img; + } + + + + public static int identifiepanneau(Mat objetrond){ + double [] scores=new double [6]; + int indexmax=-1; + if (objetrond!=null){ + 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"); + + double scoremax=scores[0]; + + for(int j=1;jscoremax){scoremax=scores[j];indexmax=j;}} + + + } + return indexmax; + } + + +} \ No newline at end of file diff --git a/TutoOpenCv/src/Fonctions.java b/TutoOpenCv/src/Fonctions.java new file mode 100644 index 0000000..f7b2b63 --- /dev/null +++ b/TutoOpenCv/src/Fonctions.java @@ -0,0 +1,115 @@ +import java.awt.Dimension; +import java.awt.Image; +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Random; +import java.util.Vector; + +import javax.imageio.ImageIO; +import javax.swing.ImageIcon; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; + +import org.opencv.core.Core; +import org.opencv.core.CvType; +import org.opencv.core.Mat; +import org.opencv.core.MatOfByte; +import org.opencv.core.MatOfDMatch; +import org.opencv.core.MatOfInt4; +import org.opencv.core.MatOfKeyPoint; +import org.opencv.core.MatOfPoint; +import org.opencv.core.MatOfPoint2f; +import org.opencv.core.Point; +import org.opencv.core.Rect; +import org.opencv.core.Scalar; +import org.opencv.core.Size; +import org.opencv.features2d.DMatch; +import org.opencv.features2d.DescriptorExtractor; +import org.opencv.features2d.DescriptorMatcher; +import org.opencv.features2d.FeatureDetector; +import org.opencv.features2d.Features2d; +import org.opencv.highgui.Highgui; +import org.opencv.imgproc.Imgproc; + + + +public class Fonctions { + public static ArrayList detect_panneau_image(String 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.imread(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; + + } +} diff --git a/TutoOpenCv/src/Principale.java b/TutoOpenCv/src/Principale.java index dc4ebce..9c27be3 100644 --- a/TutoOpenCv/src/Principale.java +++ b/TutoOpenCv/src/Principale.java @@ -1,5 +1,6 @@ import java.util.List; +import java.util.ArrayList; import java.util.Arrays; import org.opencv.core.*; import org.opencv.highgui.*; @@ -32,7 +33,11 @@ public static void main(String[] args) List ListeContours= MaBibliothequeTraitementImage.ExtractContours(saturee); int i=0; double [] scores=new double [6]; + + //Creation liste des panneaux + ArrayList res = new ArrayList(); //Pour tous les contours de la liste + for (MatOfPoint contour: ListeContours ){ i++; objetrond=MaBibliothequeTraitementImage.DetectForm(m,contour); @@ -51,16 +56,31 @@ public static void main(String[] args) double scoremax=-1; int indexmax=0; for(int j=0;jscoremax){scoremax=scores[j];indexmax=j;}} + if (scores[j]>scoremax){ + 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�");break; - case 1:System.out.println("Panneau 50 d�t�ct�");break; - case 2:System.out.println("Panneau 70 d�t�ct�");break; - case 3:System.out.println("Panneau 90 d�t�ct�");break; - case 4:System.out.println("Panneau 110 d�t�ct�");break; - case 5:System.out.println("Panneau interdiction de d�passer d�t�ct�");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; }} } diff --git a/TutoOpenCv/src/TestFunc.java b/TutoOpenCv/src/TestFunc.java new file mode 100644 index 0000000..ee8a8d9 --- /dev/null +++ b/TutoOpenCv/src/TestFunc.java @@ -0,0 +1,47 @@ +import java.awt.Dimension; +import java.awt.Image; +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Random; +import java.util.Vector; + +import javax.imageio.ImageIO; +import javax.swing.ImageIcon; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; + +import org.opencv.core.Core; +import org.opencv.core.CvType; +import org.opencv.core.Mat; +import org.opencv.core.MatOfByte; +import org.opencv.core.MatOfDMatch; +import org.opencv.core.MatOfInt4; +import org.opencv.core.MatOfKeyPoint; +import org.opencv.core.MatOfPoint; +import org.opencv.core.MatOfPoint2f; +import org.opencv.core.Point; +import org.opencv.core.Rect; +import org.opencv.core.Scalar; +import org.opencv.core.Size; +import org.opencv.features2d.DMatch; +import org.opencv.features2d.DescriptorExtractor; +import org.opencv.features2d.DescriptorMatcher; +import org.opencv.features2d.FeatureDetector; +import org.opencv.features2d.Features2d; +import org.opencv.highgui.Highgui; +import org.opencv.imgproc.Imgproc; + +public class TestFunc{ + public static void main(String[] args){ + Fonctions.detect_panneau_image("/Users/ibrahim/Java_Project/TutoOpenCv/assets/p10.jpg"); + + + } +} \ No newline at end of file