Bonjour,
je travaille dans "public class DUImg extends BufferedImage{"
Je suis donc un extends de BufferedImage.
Le but de ma fonction est de savoir si ou se trouve la sous-image.
imgSub contient donc une image de type BufferedImage
Pour éviter les problèmes d'approximation, je travaille sur des bmp.
Dans le cas ou l'image n'est pas trouvée, je renvoi un tableau contenant -1/-1
J'ai donc une complexité dans le pire des cas de :
this.h * this.w * sub.h * sub.w
Pour accélérer mon code, j'ai donc ajouté les lignes :
( visible dans le code de la fonction en commentaire. )
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 width_end -= imgSub.getWidth()-1; height_end -= imgSub.getWidth()-1;
Placé hors boucle pour éviter d'avoir ma zone de recherche qui diminue, je compte ainsi obtenir une complexités de :
(this.h-sub.h+1) * (this.w-sub.w+1) * sub.h * sub.w
Loin d'être parfait, mais déjà nettement mieux.
Mon probléme, je ne trouve plus les sous-images dans une image.
Pourquoi ?
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 public Integer[] findInto(BufferedImage imgSub, Integer width_ini, Integer height_ini, Integer width_end, Integer height_end) { Integer[] posi = new Integer[2]; posi[0] = -1; posi[1] = -1; // L'image peut-elle être contenu ? if ( width_end-width_ini<imgSub.getWidth() ) return posi; if ( height_end-height_ini<imgSub.getHeight() ) return posi; // Accélération des conditions de recherche : /* width_end -= imgSub.getWidth()-1; height_end -= imgSub.getWidth()-1; */ // Recherche : Boolean test = null; for(int width=width_ini ; width<width_end ; width++){ for(int height=height_ini ; height<height_end ; height++){ test = true; for(int widthSub=0 ; widthSub<imgSub.getWidth() ; widthSub++){ for(int heightSub=0 ; heightSub<imgSub.getHeight() ; heightSub++){ if ( this.getRGB(width+widthSub, height+heightSub) != imgSub.getRGB(widthSub, heightSub) ) { test = false; widthSub = imgSub.getWidth(); heightSub = imgSub.getHeight(); } } } if ( test ) { posi[0] = width; posi[1] = height; return posi; } } } return posi;// false }







Répondre avec citation




Partager