Page 1 sur 1
[...]PixelGetColor & Speed
Posté : lun. 29 juin 2009 02:09
par DidUngar
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.
Re: [...]PixelGetColor & Speed
Posté : lun. 29 juin 2009 02:23
par Iste
une idée serait de pas passer par des fonction graphique...
L'udf FF.au3 doit bien pouvoir faire ce que tu cherche
Les fonction graphiques sont a utiliser en dernier recoure, meme si tout le monde semble se jeter sur ca en 1er
Du moins pour le "Détécter la barre verte de chargement de firefox"
car je vois pas de quoi il sagit ^^' et je comprend pas non plus la démarche d'apres :/ encore moins cette histoire d'argent :\
Enfin, ca c'est pas mon probleme ^^
Re: [...]PixelGetColor & Speed
Posté : lun. 29 juin 2009 02:37
par DidUngar
La barre verte est la barre de chargement de firefox.
donc si je la trouve je peut savoir ou en est le chargement.
Pour la partie transformation et balade de l'image c'est sur que hors de mon réseaux ca doit paraître bizard.
Pour les sous en faites :
http://www.shotbot.fr/ propose des ascreens gratuit mais en petite quantitée.
Ensuite il les vends se qui est normal.
Ayant un gros site donc beaucoup de ascreens a faire (
http://www.monautosurf.com ) je désire devenir indépendant sur la génération d'ascreen.
NB : ascreen : Image de type png de taille réduite , cette image est une capture d'écrant d'un site.
On l'utilise surtout pour le référencement.
J'ai trouver la librairie que tu me conseil. (
http://www.autoitscript.fr/forum/viewto ... +udf#p9139 )
Mais aimant apprendre par moi même a faire les choses j'utilise déjà la mienne.
► Afficher le texte
Code : Tout sélectionner
#cs ----------------------------------------------------------------------------
Version: 0.0.1.7
Author: DidUngar
Script Function:
Fonction de gestion de FireFox
#ce ----------------------------------------------------------------------------
Func firefox_run()
Run("C:\Program Files\Mozilla Firefox\firefox.exe","",@SW_MAXIMIZE);
$firefox_start=TimerInit();
; Le programme se lance...
Do ; Le programme se lance encore ...
Sleep(5)
If ( $firefox_start+(15*1000) >= TimerInit() ) Then
Run("C:\Program Files\Mozilla Firefox\firefox.exe","",@SW_MAXIMIZE);
$firefox_start=TimerInit();
EndIf
If ( WinActivate(WinGetTitle("Firefox")) ) Then ;
If ( StringInStr( WinGetTitle(""), "Firefox" )<>0 ) Then
WinSetOnTop(WinGetTitle(""), "", @SW_MAXIMIZE)
EndIf
EndIf
If ( StringInStr( WinGetTitle(""), "Firefox - Restauration" )<>0 ) Then
Sleep(250)
Send("{TAB}");
Sleep(250)
Send("{ENTER}");
Sleep(250)
EndIf
Until ( StringInStr( WinGetTitle(""), "Mozilla Firefox" )<>0 )
firefox_loading()
EndFunc
Func firefox_loading()
Sleep(15); Attendre que la barre de chargement s'ouvre
While ( PixelGetColor(930,729)<>PixelGetColor(730,729) ); Couleur du style de actuel
Sleep(5); Attendre un peut pour que le chargement se finnisse.
WEnd
Sleep (5); Attendre un peut pour que FireFox finisse.
EndFunc
Func firefox_url($url)
#include-once "fonct_souris.au3"
click( @DesktopWidth/2 , 70 ); Selection de la zone URL Du navigateur
Sleep(15); Effacer l'ancienne url
send("^a"); Ctrl-a
$i =0
While ( $i < 75 )
Send ( "{BACKSPACE}" )
$i = $i+1;
Wend
$i =0
While ( $i < 75 )
Send ( "{DELETE}" )
$i = $i+1;
Wend
sleep (250);
send("^a"); Ctrl-a
sleep (15);Envoyer la nouvelle url
Send($url);
Send("{ENTER}"); Charger
firefox_loading()
; Gestion des cas d'erreur
; On as taper dans google au lieu de dans l'url...
If ( StringInStr(AutoItWinGetTitle()," - Recherche Google - Mozilla Firefox")<>0 ) Then
sleep (50);
Return firefox_url($url)
EndIf
; Protocole non supporter
If ( WinWaitActive("Alerte","",1)<>0 ) Then
sleep (15);
send("{ENTER}")
sleep (50);
Return firefox_url($url)
EndIf
; Bad Request.
If ( WinWaitActive("400 Bad Request - Mozilla Firefox","",1)<>0 ) Then
sleep (15);
Return firefox_url($url)
EndIf
; Page non trouver.
If ( WinWaitActive("Erreur de chargement de la page - Mozilla Firefox","",1)<>0 ) Then
Send("{F5}")
firefox_loading()
If ( WinWaitActive("Erreur de chargement de la page - Mozilla Firefox","",1)<>0 ) Then
Return False;
EndIf
EndIf
; Url non trouver.
If ( WinWaitActive("Club Internet - Recherche - Mozilla Firefox","",1)<>0 ) Then
firefox_url($url)
EndIf
EndFunc
Func firefox_AntiPopUp()
; Qui ont était bloquez :
click(1010,125);
;Spyware Secure
If ( StringInStr( WinGetTitle(""), "Spyware" )<>0 ) Then
firefox_close_tab()
EndIf
;Titan Poker
If ( StringInStr( WinGetTitle(""), "Titan Poker" )<>0 ) Then
firefox_close_tab()
EndIf
;hangrohe
If ( StringInStr( WinGetTitle(""), "PlaytheGAME Grand Concours" )<>0 ) Then
firefox_close_tab()
EndIf
;Dial Messenger
If ( StringInStr( WinGetTitle(""), "Dial" )<>0 ) Then
firefox_close_tab()
EndIf
;Yes! Messenger
If ( StringInStr( WinGetTitle(""), "Yes!Messenger" )<>0 ) Then
firefox_close_tab()
EndIf
;Navi-Search
If ( StringInStr( WinGetTitle(""), "Navi-Search" )<>0 ) Then
firefox_close_tab()
EndIf
;Bouygues
If ( StringInStr( WinGetTitle(""), "Bouygues" )<>0 ) Then
firefox_close_tab()
EndIf
;Banque
If ( StringInStr( WinGetTitle(""), "USAFIS" )<>0 ) Then
firefox_close_tab()
EndIf
EndFunc
Func firefox_is()
Return ( StringInStr( WinGetTitle(""), "Mozilla Firefox" )<>0 )
EndFunc
Func firefox_wait()
While (firefox_is()<>True)
Sleep(5)
WEnd
EndFunc
Func firefox_clean()
Send("^+{DEL}")
Sleep(15)
Send("{TAB}")
Send("{TAB}")
Send("{TAB}")
Send("{TAB}")
Send("{TAB}")
Send("{TAB}")
Send("{TAB}")
Sleep(15)
Send("{ENTER}")
Sleep(15)
EndFunc
Func firefox_certificat()
If ( StringInStr( WinGetTitle(""), "Site Web certifi� par une autorit� inconnue" )<>0 ) Then
Sleep(15)
Send("{ENTER}")
Sleep(15)
Return True;
EndIf
Return False;
EndFunc
Func firefox_new_tab()
If ( firefox_is()<>True ) Then
Return False;
EndIf
Send("^t");
Return True;
EndFunc
Func firefox_close_tab()
If ( firefox_is()<>True ) Then
Return False;
EndIf
Send("^w");
Return True;
EndFunc
Func firefox_close() ; Ferme la fenetre active si c'est firefox.
If ( firefox_is()<>True ) Then
Return False;
EndIf
WinSetState ( WinGetTitle(""), "", @SW_MAXIMIZE )
Send("!{F4}")
; Gestion des erreurs
; Secu multi onglet
If ( StringInStr( WinGetTitle(""),"Confirmer la fermeture" )<>0 ) Then
Sleep(25)
Send("{ENTER}")
Sleep(15)
EndIf
Return (firefox_is()<>True);
EndFunc
Func firefox_get_page()
click(25,125)
Sleep(25)
send("^a"); Ctrl-a
Sleep(25)
send("^c"); Ctrl-c
Sleep(25)
return ClipGet()
EndFunc
On peut remarquer que : firefox_loading() ne tient pas compte de la position de la barre de chargement.
D'ou mon travail sur la detection d'image.
Re: [...]PixelGetColor & Speed
Posté : lun. 29 juin 2009 02:41
par Iste
ha dac je comprend, tu veux faire un truc que les autres font payer, je comprend ^^
Bon alors, comme t'as l'air de vraiment faire comme ca, du moins pour essayer, l'idéal serait de prendre les coordonnées de la fenêtre de chargement avant de lancer la recherche !
comme ca ca l'imite, ou qu'elle soit
Mais maintenant j'en suis encore plus persuadé, c'est pas la bonne solution :p
Edit : dis en fait, et si tu inetget() la page ? pas bon ?
Re: [...]PixelGetColor & Speed
Posté : lun. 29 juin 2009 02:47
par DidUngar
Je suis tous as fait d'accord sur le faite que rétrécir la zone de recherche va nettement accelérée.
c'est d'ailleur pour cela que j'ai placer les arguments : ,$x_ini,$y_ini,$x_end,$y_end
Mais lors des test je préfére prendre de grande zone pour mieu faire les stats.
Et c'est la que j'ai remarquer ce phénoméne bizard getPix qui même en C est réputer extremement lent est plus rapide qu'une mise en ram des informations.
C'est pour comprendre se phénoméne que je suis venu poster.
Re: [...]PixelGetColor & Speed
Posté : lun. 29 juin 2009 02:53
par Iste
ha, bon ben dans ce cas je peux pas t'aider désolé ^^
mais si un jour tu cherche a faire un script pour le faire fonctionner, et non pour l'observer tel un rat dans un labyrinthe, je serais la

Re: [...]PixelGetColor & Speed
Posté : lun. 29 juin 2009 02:54
par Tlem
@DidUngar
Merci de mettre vos balise de code dans des balises spoiler lorsque votre code dépasse un dizaine de ligne.
Re: [...]PixelGetColor & Speed
Posté : lun. 29 juin 2009 03:00
par DidUngar
Iste a écrit :ha, bon ben dans ce cas je peux pas t'aider désolé ^^
mais si un jour tu cherche a faire un script pour le faire fonctionner, et non pour l'observer tel un rat dans un labyrinthe, je serais la

Merci je retient l'offre.
Tlem a écrit :@DidUngar
Merci de mettre vos balise de code dans des balises spoiler lorsque votre code dépasse un dizaine de ligne.
D'accord, je rajouterai la balise.
Re: [...]PixelGetColor & Speed
Posté : lun. 29 juin 2009 04:28
par orax
Bonsoir, alors en fait, ce que j'ai fait ce n'est pas une détection de l'image, mais juste d'un pixel. Je ne sais pas si ça pourra convenir.
Pour tester le script vous devez : lancer le script ; activer la fenêtre de Firefox et appuyer plusieurs fois sur F5 pour garder afficher la barre verte (ou blanche). Le script boucle tant que la couleur à l'emplacement de la barre verte ne sera pas grise.
Il est possible que 280 dans l'expression "$xBarreVerte=$a[2]-280" doit être modifié pour que ça marche !
Chez moi ça marche en fenêtre agrandit et normale. Voilà voila...
Je ne l'ai pas fait mais si vraiment vous voulez savoir à quel endroit se trouve la barre verte, il est possible de déterminer automatiquement la valeur 280 (dans "$xBarreVerte=$a[2]-280") avec une détection d'un pixel particulier dans la grande barre grise (la barre de statut).
Code : Tout sélectionner
Opt("PixelCoordMode",0)
$hwnd=ControlGetHandle("[CLASS:MozillaUIWindowClass]","","MozillaWindowClass1")
$a=ControlGetPos("[CLASS:MozillaUIWindowClass]","","MozillaWindowClass1")
$xBarreVerte=$a[2]-280 ; IMPORTANT : à modifier selon votre Firefox
$yBarreVerte=$a[3]-10
Sleep(2000)
;~ ClipPut(PixelGetColor($xBarreVerte,$yBarreVerte,$hwnd)) ; 0x00DFE0E5 = 14672101 = couleur grise
While PixelGetColor($xBarreVerte,$yBarreVerte,$hwnd) <> 14672101 ;
Sleep(100)
WEnd
Re: [...]PixelGetColor & Speed
Posté : lun. 29 juin 2009 07:59
par DidUngar
Ce qui m'interesse serai de ne plus avoir "à modifier selon votre Firefox".
Mon détecteur d'image fonctionne bien.
Mais je ne comprend pas le changement de vitesse qui s'oppére lorsque j'utilise un cache.
( J'admet que lorsque je met juste la ligne du bas du navigateur je met moin de 1 seconde a trouver la barre de chargement ,
mon probléme est donc purement un probléme de compréhention )
Re: [...]PixelGetColor & Speed
Posté : lun. 29 juin 2009 19:14
par orax
DidUngar a écrit :Ce qui m'interesse serai de ne plus avoir "à modifier selon votre Firefox".
Il n'y a qu'une ligne à rajouter :
► Afficher le texte
Code : Tout sélectionner
Opt("PixelCoordMode",0)
WinActivate("[CLASS:MozillaUIWindowClass]","")
WinWaitActive("[CLASS:MozillaUIWindowClass]","")
$hwnd=ControlGetHandle("[CLASS:MozillaUIWindowClass]","","MozillaWindowClass1")
$a=ControlGetPos("[CLASS:MozillaUIWindowClass]","","MozillaWindowClass1")
MsgBox(0,"","Commencer la détection...")
$b=PixelSearch(0,$a[3]-10,$a[2],$a[3],0xFFFFFF,0,1,$hwnd) ; emplacement de la première barre verticale
MsgBox(0,"","emplacement de la barre verticale trouvé à " & $b[0] & @CRLF & "il faut maintenant appuyer sur F5 !")
$xBarreVerte=$b[0]-80
$yBarreVerte=$a[3]-10
Sleep(1000)
While PixelGetColor($xBarreVerte,$yBarreVerte,$hwnd) <> 14672101
Sleep(100)
WEnd
Re: [...]PixelGetColor & Speed
Posté : mar. 30 juin 2009 08:31
par DidUngar
Merci mais,
Tu demande a 2 reprise a l'utilisateur d'intervenir.
Et tu ne prend pas en compte les différent templatte.
De plus trouver la barre verte j'y arrive je demande juste a comprendre pourquoi mon script est plus lent avec un cache que sans.
Je ne vous demande pas de résoudre mon probléme final mais juste de m'aider a comprendre le ralentissement du script.