IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Android Discussion :

Expliquer cette méthode de reconnaissance


Sujet :

Android

  1. #1
    Membre à l'essai
    Homme Profil pro
    Inscrit en
    Septembre 2013
    Messages
    32
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Septembre 2013
    Messages : 32
    Points : 18
    Points
    18
    Par défaut Expliquer cette méthode de reconnaissance
    Bonjour,

    J'ai développé une application qui fait la comparaison entre deux images. J'ai utilisé opencv pour la détection du visage sur l'image et l'image existe en base de données. J'aimerais bien résoudre ces problèmes mais j'ai une méthode que je ne comprends pas.

    Merci d'avance pour votre aide.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    public  class PersonRecognizer {
     
    	public final static int MAXIMG = 100;
    	FaceRecognizer faceRecognizer;
    	String mPath;
    	int count=0;
    	labels labelsFile;
     
    	 static  final int WIDTH= 128;
    	 static  final int HEIGHT= 128;;
    	 private int mProb=999;
     
     
        PersonRecognizer(String path)
        {
          faceRecognizer =  com.googlecode.javacv.cpp.opencv_contrib.createLBPHFaceRecognizer(2,8,8,8,200);
      	// path=Environment.getExternalStorageDirectory()+"/facerecog/faces/";
         mPath=path;
         labelsFile= new labels(mPath);
     
     
        }
     
        void changeRecognizer(int nRec)
        {
        	switch(nRec) {
        	case 0: faceRecognizer = com.googlecode.javacv.cpp.opencv_contrib.createLBPHFaceRecognizer(1,8,8,8,100);
        			break;
        	case 1: faceRecognizer = com.googlecode.javacv.cpp.opencv_contrib.createFisherFaceRecognizer();
        			break;
        	case 2: faceRecognizer = com.googlecode.javacv.cpp.opencv_contrib.createEigenFaceRecognizer();
        			break;
        	}
        	train();
     
        }
     
    	void add(Mat m, String description) {
    		Bitmap bmp= Bitmap.createBitmap(m.width(), m.height(), Bitmap.Config.ARGB_8888);
     
    		Utils.matToBitmap(m,bmp);
    		bmp= Bitmap.createScaledBitmap(bmp, WIDTH, HEIGHT, false);
     
    		FileOutputStream f;
    		try {
    			f = new FileOutputStream(mPath+description+"-"+count+".jpg",true);
    			count++;
    			bmp.compress(Bitmap.CompressFormat.JPEG, 100, f);
    			f.close();
     
    		} catch (Exception e) {
    			Log.e("error",e.getCause()+" "+e.getMessage());
    			e.printStackTrace();
     
    		}
    	}
     
    	public boolean train() {
     
    		File root = new File(mPath);
     
            FilenameFilter pngFilter = new FilenameFilter() {
                public boolean accept(File dir, String name) {
                    return name.toLowerCase().endsWith(".jpg");
     
            };
            };
     
            File[] imageFiles = root.listFiles(pngFilter);
     
            MatVector images = new MatVector(imageFiles.length);
     
            int[] labels = new int[imageFiles.length];
     
            int counter = 0;
            int label;
     
            IplImage img=null;
            IplImage grayImg;
     
            int i1=mPath.length();
     
     
            for (File image : imageFiles) {
            	String p = image.getAbsolutePath();
                img = cvLoadImage(p);
     
                if (img==null)
                	Log.e("Error","Error cVLoadImage");
                Log.i("image",p);
     
                int i2=p.lastIndexOf("-");
                int i3=p.lastIndexOf(".");
                int icount=Integer.parseInt(p.substring(i2+1,i3)); 
                if (count<icount) count++;
     
                String description=p.substring(i1,i2);
     
                if (labelsFile.get(description)<0)
                	labelsFile.add(description, labelsFile.max()+1);
     
                label = labelsFile.get(description);
     
                grayImg = IplImage.create(img.width(), img.height(), IPL_DEPTH_8U, 1);
     
                cvCvtColor(img, grayImg, CV_BGR2GRAY);
     
                images.put(counter, grayImg);
     
                labels[counter] = label;
     
                counter++;
            }
            if (counter>0)
            	if (labelsFile.max()>=1)
            		faceRecognizer.train(images, labels);
            labelsFile.Save();
    	return true;
    	}
     
    	public boolean canPredict()
    	{
    		if (labelsFile.max()>=1)
    			return true;
    		else
    			return false;
     
    	}
     
    	public String predict(Mat m) {
    		if (!canPredict())
    			return "";
    		int n[] = new int[1];
    		double p[] = new double[1];
    		IplImage ipl = MatToIplImage(m,WIDTH, HEIGHT);
    //		IplImage ipl = MatToIplImage(m,-1, -1);
     
    		faceRecognizer.predict(ipl, n, p);
     
    		if (n[0]!=-1)
    		 mProb=(int)p[0];
    		else
    			mProb=-1;
    	//	if ((n[0] != -1)&&(p[0]<95))
    		if (n[0] != -1)
    			return labelsFile.get(n[0]);
    		else
    			return "pas reconu";
    	}
     
     
     
     
    	  IplImage MatToIplImage(Mat m,int width,int heigth)
    	  {
     
     
    		   Bitmap bmp=Bitmap.createBitmap(m.width(), m.height(), Bitmap.Config.ARGB_8888);
     
     
    		   Utils.matToBitmap(m, bmp);
    		   return BitmapToIplImage(bmp,width, heigth);
     
    	  }
     
    	IplImage BitmapToIplImage(Bitmap bmp, int width, int height) {
     
    		if ((width != -1) || (height != -1)) {
    			Bitmap bmp2 = Bitmap.createScaledBitmap(bmp, width, height, false);
    			bmp = bmp2;
    		}
     
    		IplImage image = IplImage.create(bmp.getWidth(), bmp.getHeight(),
    				IPL_DEPTH_8U, 4);
     
    		bmp.copyPixelsToBuffer(image.getByteBuffer());
     
    		IplImage grayImg = IplImage.create(image.width(), image.height(),
    				IPL_DEPTH_8U, 1);
     
    		cvCvtColor(image, grayImg, opencv_imgproc.CV_BGR2GRAY);
     
    		return grayImg;
    	}
     
     
     
    	protected void SaveBmp(Bitmap bmp,String path)
    	  {
    			FileOutputStream file;
    			try {
    				file = new FileOutputStream(path , true);
     
    			bmp.compress(Bitmap.CompressFormat.JPEG,100,file); 	
    		    file.close();
    			}
    		    catch (Exception e) {
    				// TODO Auto-generated catch block
    		    	Log.e("",e.getMessage()+e.getCause());
    				e.printStackTrace();
    			}
     
    	  }
     
     
    	public void load() {
    		train();
     
    	}
     
    	public int getProb() {
    		// TODO Auto-generated method stub
    		return mProb;
    	}
     
     
    }
    et merci d'avance

  2. #2
    Expert éminent

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Points : 9 149
    Points
    9 149
    Par défaut
    Salut,

    Quelle méthode ?
    Responsable Android de Developpez.com (Twitter et Facebook)
    Besoin d"un article/tutoriel/cours sur Android, consulter la page cours
    N'hésitez pas à consulter la FAQ Android et à poser vos questions sur les forums d'entraide mobile d'Android.

  3. #3
    Membre à l'essai
    Homme Profil pro
    Inscrit en
    Septembre 2013
    Messages
    32
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Septembre 2013
    Messages : 32
    Points : 18
    Points
    18
    Par défaut
    ca

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    public String predict(Mat m) {
    		if (!canPredict())
    			return "";
    		int n[] = new int[1];
    		double p[] = new double[1];
    		IplImage ipl = MatToIplImage(m,WIDTH, HEIGHT);
    //		IplImage ipl = MatToIplImage(m,-1, -1);
     
    		faceRecognizer.predict(ipl, n, p);
     
    		if (n[0]!=-1)
    		 mProb=(int)p[0];
    		else
    			mProb=-1;
    	//	if ((n[0] != -1)&&(p[0]<95))
    		if (n[0] != -1)
    			return labelsFile.get(n[0]);
    		else
    			return "pas reconu";
    	}
    Merci.

Discussions similaires

  1. [Débutant] Pouvez-vous m'expliquer cette méthode sur les expressions
    Par jacko842 dans le forum C#
    Réponses: 4
    Dernier message: 27/05/2015, 12h44
  2. Réponses: 5
    Dernier message: 30/04/2015, 12h38
  3. Ne gere pas cette propriété ou cette méthode
    Par starr dans le forum Général JavaScript
    Réponses: 16
    Dernier message: 15/10/2007, 17h55
  4. [Jscript]Cet objet ne gère pas cette propriété ou cette méthode
    Par 1tox dans le forum Général JavaScript
    Réponses: 9
    Dernier message: 02/06/2006, 10h19
  5. expliqué cette requête
    Par ismailsalam dans le forum Décisions SGBD
    Réponses: 4
    Dernier message: 29/09/2005, 15h10

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo