Bonjour,
J'ai tenter d'optimiser une fonction de comparaison d'image
L'image a trouver est la poubelle windows ( donc placer en haut de l'écrant )
Sur l'ancienne version je met une moyenne ( sur 10 test ) de 23190 ( seconde ? ) pour la trouver
Sur la nouvelle version je met 24 480 pour la trouver.
Pourtant la fonction PixelGetColor est réputer comme étant lente, et je stoque ses résultats dans un tableaux 2 dimentions pour accélérée le résultat.
Auriez-vous une explication ?
version Beta :
► Afficher le texte
Code : Tout sélectionner
Func img_findFileScreen($f1,$x_ini,$y_ini,$x_end,$y_end)
return img_P3findFileScreen($f1,$x_ini,$y_ini,$x_end,$y_end)
EndFunc
Func img_P3findFileScreen($f1,$x_ini,$y_ini,$x_end,$y_end)
Dim $return[2]
$return[0]=-1;
$return[1]=-1;
$h1 = FileOpen($f1,0)
If ( $h1==-1 ) Then Return $return;
; Format :
$l1 = FileReadLine($h1)
If ( $l1 <> 'P3' ) Then
FileClose($h1)
Return $return;
EndIf
; Largeur :
$l1 = FileReadLine($h1)
$x_max = $l1;
If ( $l1 > $x_end-$x_ini+1 ) Then
FileClose($h1)
Return $return;
EndIf
; Hauteur :
$l1 = FileReadLine($h1)
$y_max = $l1;
If ( $l1 > $y_end-$y_ini+1 ) Then
FileClose($h1)
Return $return;
EndIf
;Valeur Maxi des couleurs
$l1 = FileReadLine($h1)
If ( $l1 <> 255 ) Then
FileClose($h1)
Return $return;
EndIf
FileClose($h1)
Dim $screen[@DesktopWidth+1][@DesktopHeight+1];
; Analyse des couleurs :
For $y_now = $y_ini To ($y_end-$y_max+1) Step 1
$l_temp = '';
$l1 = FileReadLine($h1)
For $x_now = $x_ini To ($x_end-$x_max+1) Step 1
ToolTip($f1&' -> '&$x_now&'/'&$x_end&' '&$y_now&'/'&$y_end, 0, 0);
; Comparaison :
$h_sub = FileOpen($f1,0)
If ( $h_sub==-1 ) Then
$return[1]='Error Open...';
Return $return;
EndIf
$l_sub = FileReadLine($h_sub); Format
$l_sub = FileReadLine($h_sub); Largeur
$l_sub = FileReadLine($h_sub); Hauteur
$l_sub = FileReadLine($h_sub); Valeur Maxi des couleurs
$test = 1;
$xSub_ini=$x_now
$xSub_end=$x_now+$x_max-1
$ySub_ini=$y_now
$ySub_end=$y_now+$y_max-1
; Analyse des couleurs :
For $ySub_now = $ySub_ini To $ySub_end Step 1
$l_sub = FileReadLine($h_sub)
$p = stringsplit($l_sub,' ');
For $xSub_now = $xSub_end To $xSub_ini Step -1
If ( Not $screen[$xSub_now][$ySub_now] ) Then
$screen[$xSub_now][$ySub_now] = PixelGetColor($xSub_now,$ySub_now);
EndIf
$color_screen = $screen[$xSub_now][$ySub_now];PixelGetColor($xSub_now,$ySub_now);
$rvb = stringsplit($p[$xSub_now-$xSub_ini+1],' ');
$color_text = img_rvb2color($rvb[1],$rvb[2],$rvb[3])
If ( $color_text <> $color_screen ) Then
FileClose($h_sub)
$test = 0
ExitLoop;
EndIf
Next
If ( $test == 0 ) Then
ExitLoop;
EndIf
Next
FileClose($h_sub)
If ( $test == 1 ) Then
; On as trouver l'image :
$return[0]=$x_now;
$return[1]=$y_now;
return $return;
EndIf
Next
Next
return $return;
EndFunc
Version stable :
► Afficher le texte
Code : Tout sélectionner
Func img_findFileScreen($f1,$x_ini,$y_ini,$x_end,$y_end)
return img_P3findFileScreen($f1,$x_ini,$y_ini,$x_end,$y_end)
EndFunc
Func img_P3findFileScreen($f1,$x_ini,$y_ini,$x_end,$y_end)
Dim $return[2]
$return[0]=-1;
$return[1]=-1;
$h1 = FileOpen($f1,0)
If ( $h1==-1 ) Then Return $return;
; Format :
$l1 = FileReadLine($h1)
If ( $l1 <> 'P3' ) Then
FileClose($h1)
Return $return;
EndIf
; Largeur :
$l1 = FileReadLine($h1)
$x_max = $l1;
If ( $l1 > $x_end-$x_ini+1 ) Then
FileClose($h1)
Return $return;
EndIf
; Hauteur :
$l1 = FileReadLine($h1)
$y_max = $l1;
If ( $l1 > $y_end-$y_ini+1 ) Then
FileClose($h1)
Return $return;
EndIf
;Valeur Maxi des couleurs
$l1 = FileReadLine($h1)
If ( $l1 <> 255 ) Then
FileClose($h1)
Return $return;
EndIf
FileClose($h1)
; Analyse des couleurs :
For $y_now = $y_ini To ($y_end-$y_max+1) Step 1
$l_temp = '';
$l1 = FileReadLine($h1)
For $x_now = $x_ini To ($x_end-$x_max+1) Step 1
ToolTip($f1&' -> '&$x_now&'/'&$x_end&' '&$y_now&'/'&$y_end, 0, 0);
; Comparaison :
$h_sub = FileOpen($f1,0)
If ( $h_sub==-1 ) Then
$return[1]='Error Open...';
Return $return;
EndIf
$l_sub = FileReadLine($h_sub); Format
$l_sub = FileReadLine($h_sub); Largeur
$l_sub = FileReadLine($h_sub); Hauteur
$l_sub = FileReadLine($h_sub); Valeur Maxi des couleurs
$test = 1;
$xSub_ini=$x_now
$xSub_end=$x_now+$x_max-1
$ySub_ini=$y_now
$ySub_end=$y_now+$y_max-1
; Analyse des couleurs :
For $ySub_now = $ySub_ini To $ySub_end Step 1
$l_sub = FileReadLine($h_sub)
$p = stringsplit($l_sub,' ');
For $xSub_now = $xSub_ini To $xSub_end Step 1
$color_screen = PixelGetColor($xSub_now,$ySub_now);
$rvb = stringsplit($p[$xSub_now-$xSub_ini+1],' ');
$color_text = img_rvb2color($rvb[1],$rvb[2],$rvb[3])
If ( $color_text <> $color_screen ) Then
FileClose($h_sub)
$test = 0
ExitLoop;
EndIf
Next
If ( $test == 0 ) Then
ExitLoop;
EndIf
Next
FileClose($h_sub)
If ( $test == 1 ) Then
; On as trouver l'image :
$return[0]=$x_now;
$return[1]=$y_now;
return $return;
EndIf
Next
Next
return $return;
EndFunc
Et bien sur l'outils de test :
► Afficher le texte
Code : Tout sélectionner
#include "fonct_img.au3"
;For $i=0 To (256*256*256-1) Step 1
; $rvb = img_color2rvb($i);
; $color = img_rvb2color($rvb[0],$rvb[1],$rvb[2])
; If ( $color <> $i) Then
; MsgBox(0,'Erreur',$i&' '&$color);
; EndIf
;Next
;img_findFileScreen('img.ppm',0,0,@DesktopWidth,@DesktopHeight)
$time = TimerInit()
$posi = img_findFileScreen('img.ppm',0,0,@DesktopWidth,@DesktopHeight)
$posi = img_findFileScreen('img.ppm',0,0,@DesktopWidth,@DesktopHeight)
$posi = img_findFileScreen('img.ppm',0,0,@DesktopWidth,@DesktopHeight)
$posi = img_findFileScreen('img.ppm',0,0,@DesktopWidth,@DesktopHeight)
$posi = img_findFileScreen('img.ppm',0,0,@DesktopWidth,@DesktopHeight)
$posi = img_findFileScreen('img.ppm',0,0,@DesktopWidth,@DesktopHeight)
$posi = img_findFileScreen('img.ppm',0,0,@DesktopWidth,@DesktopHeight)
$posi = img_findFileScreen('img.ppm',0,0,@DesktopWidth,@DesktopHeight)
$posi = img_findFileScreen('img.ppm',0,0,@DesktopWidth,@DesktopHeight)
$posi = img_findFileScreen('img.ppm',0,0,@DesktopWidth,@DesktopHeight)
$time = TimerDiff($time)
$time = $time /10
MsgBox(0,'Placement : '&$time,$posi[0]&' '&$posi[1]);
Le but final du script :
Détécter la barre verte de chargement de firefox pour prendre une capture d'érant une fois le DL d'une page web terminée
Envoyer le resultat via FTP sur un linux qui serai cronner pour convertir l'image en bmp via perl et ensuite la redimentionner en php pour en faire un ascreen.
Oui la solution est longue est imprafaite mais sinon je doit payer 1€ Les 1000 ascreen.
Alors que si je peut l'optimiser je pourrai faire les ascreen des mes sites automatiquement et plus réguliérement.
( soit 400 ascreen en moyenne par mois )
Je suis prenneur de vos idées.
Merci d'avance.