Skip to content

Commit

Permalink
fonction_detectionV1
Browse files Browse the repository at this point in the history
  • Loading branch information
Ibou42 committed May 8, 2023
1 parent 4622754 commit bdc9b37
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 60 deletions.
Binary file modified TutoOpenCv/.DS_Store
Binary file not shown.
Binary file modified TutoOpenCv/bin/AnalyseVideo.class
Binary file not shown.
Binary file modified TutoOpenCv/bin/Fonctions.class
Binary file not shown.
Binary file modified TutoOpenCv/bin/MaBibliothequeTraitementImage.class
Binary file not shown.
Binary file not shown.
Binary file modified TutoOpenCv/bin/Principale.class
Binary file not shown.
Binary file removed TutoOpenCv/bin/Principale_DEUX.class
Binary file not shown.
Binary file modified TutoOpenCv/bin/TestFunc.class
Binary file not shown.
66 changes: 26 additions & 40 deletions TutoOpenCv/src/AnalyseVideo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<MatOfPoint> 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<MatOfPoint> 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();
}
}




Expand Down Expand Up @@ -122,9 +106,11 @@ public static int identifiepanneau(Mat objetrond){
double scoremax=scores[0];

for(int j=1;j<scores.length;j++){
if (scores[j]>scoremax){scoremax=scores[j];indexmax=j;}}


if (scores[j]>scoremax){
scoremax=scores[j];
indexmax=j;
}
}
}
return indexmax;
}
Expand Down
96 changes: 96 additions & 0 deletions TutoOpenCv/src/Fonctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,100 @@ public static ArrayList<Mat> detect_panneau_image(String fichier){
return res;

}

public static ArrayList<Mat> detect_panneau_imagebis(Mat fichier){
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
ArrayList<Mat> res = new ArrayList<Mat>();
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<MatOfPoint> 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;j<scores.length;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�");
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<Mat> detect_panneau_video(String fichier){
ArrayList<Mat> res = new ArrayList<Mat>();

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();
}
}

}
21 changes: 5 additions & 16 deletions TutoOpenCv/src/MaBibliothequeTraitementImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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<MatOfPoint> ExtractContours(Mat input) {
// Detecter les contours des formes trouv�es
int thresh = 100;
Expand Down Expand Up @@ -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 );
Expand All @@ -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) {

Expand Down Expand Up @@ -260,13 +257,5 @@ public static double tauxDeSimilitude(Mat object,String signfile) {

}









}

6 changes: 2 additions & 4 deletions TutoOpenCv/src/Principale.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.opencv.core.*;
import org.opencv.highgui.*;
import utilitaireAgreg.MaBibliothequeTraitementImage;

public class Principale {

public static void main(String[] args)
Expand All @@ -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
Expand Down Expand Up @@ -82,10 +83,7 @@ public static void main(String[] args)
res.add(Highgui.imread("/Users/ibrahim/Java_Project/TutoOpenCv/assets/refdouble.jpg"));
break;
}}

}
}


}
}
1 change: 1 addition & 0 deletions TutoOpenCv/src/TestFunc.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");


}
Expand Down

0 comments on commit bdc9b37

Please sign in to comment.