Jump to content

Function image declaration and OCR.


Recommended Posts

Hi all.

I created a function which record the color of each pixel of an reference image (cf script 1: Function image declaration) and I would like that with another function (that I will encrust in the 1st script later) I can detect the 1st pixel of this image by looking if each color of each pixel of the image was scaned to correspond (cf scipt 2: OCR (Optical Character Recognition) for to detect this image and his 1st pixel of a reference image).

Function image declaration:

Func declaration_image_de_reference_($nom_de_image_reference,$format, $coord_image_reference_x_haut_gauche,$coord_image_reference_y_haut_gauche, $largeur_image_de_reference,$longueur_image_de_reference);(mettre le nom de l'image qui se trouve dans le dossier @DesktopDir & "\Images pour le bot dofus\", son format,abscisse du pixel de départ qui doit être scanné, ordonnée = idem, largeur de l'image, longueur de l'image)

    SplashImageOn("test",@DesktopDir & "\Images pour le bot dofus\" & $nom_de_image_reference & $format,$largeur_image_de_reference,$longueur_image_de_reference,$coord_image_reference_x_haut_gauche,$coord_image_reference_y_haut_gauche );on doit avoir déjà créé un dossier sur le bureau se nommant "Images pour le bot dofus" où il y aura l'image de réference
    Sleep(500)

Local $image_de_reference[$largeur_image_de_reference][$longueur_image_de_reference]

        For $coord_x_compteur = 0 To $largeur_image_de_reference - 1
            For $coord_y_compteur = 0 To $longueur_image_de_reference - 1
                $image_de_reference[$coord_x_compteur][$coord_y_compteur] = Hex(PixelGetColor($coord_image_reference_x_haut_gauche + 4,$coord_image_reference_y_haut_gauche + 29), 6);+4 et +29 car il y a la barre de texte
                $coord_image_reference_y_haut_gauche = $coord_image_reference_y_haut_gauche + 1
            Next
            $coord_image_reference_x_haut_gauche = $coord_image_reference_x_haut_gauche + 1
            $coord_image_reference_y_haut_gauche = $coord_image_reference_y_haut_gauche - $longueur_image_de_reference
        Next
    
    Sleep(500)
    SplashOff()
    Sleep(500)

EndFunc

;voir pour changer le nom de la variable où sont enregistrer les couleurs pour qu'il corresponde avec celui de l'image
;à vérifier pour les - 1
;on doit avoir déjà créé un dossier sur le bureau se nommant "Images pour le bot dofus" où il y aura l'image de réference

I tested it and that posts me the image which I want to record the color with each pixel and no error message is posted.

Function OCR (Optical Character Recognition) allowing to detect the 1st pixel of an reference image:

Func OCR_image_de_reference_pour_recolter($pixel_verification_haut_gauche_image,$image_de_reference,$largeur_image_de_reference_a_detecte,$longueur_image_de_reference_a_detecte);à completer ou changer

$pixel_verification_haut_gauche_image = PixelSearch(49, 48,973, 581,$color_image_haut_gauche)
    If Not @error Then

        For $coord_x_compteur = 0 To $largeur_image_de_reference_a_detecte - 1
            For $coord_y_compteur = 0 To $longueur_image_de_reference_a_detecte - 1
                If $image_de_reference[$coord_x_compteur][$coord_y_compteur] <> Hex(PixelGetColor($pixel_verification_haut_gauche_image[0],$pixel_verification_haut_gauche_image[1]), 6) Then
                    ExitLoop(2);mettre quelque chose d'autre pour dire que l'image n'a pas été trouvé et donc...
                    $pixel_verification_haut_gauche_image <> $pixel_haut_gauche_image
                Else
                    ContinueLoop
                EndIf
                $pixel_verification_haut_gauche_image[1] = $pixel_verification_haut_gauche_image[1] + 1
            Next
            $pixel_verification_haut_gauche_image[0] = $pixel_verification_haut_gauche_image[0] + 1
            $pixel_verification_haut_gauche_image[1] = $pixel_verification_haut_gauche_image[1] - $longueur_image_de_reference_a_detecte - 1
        Next
        
    Else
    
    $pixel_verification_haut_gauche_image <> $pixel_haut_gauche_image

    EndIf
    
EndFunc

;on peut s'en servir après en mettant par exemple  If $pixel_verification_haut_gauche_image = $pixel_haut_gauche_image Then
                                                    ;MouseMove($pixel_haut_gauche_image[0],$pixel_haut_gauche_image[1])
                                                    ;Sleep(500)
                                                    ;MouseClick("left")
                                                    ;Sleep(500)
                                                    ;etc...

I would like, if all the colors correspond to all the pixels that says to me that the image corresponds and that else (it is especially there that I block) that says to me that does not correspond (when I use the verb to say, I do not want to speak about a ordering of the MsgBox kind).

An example of what I want to do is for example to click with the 1st pixel of the image (if it is detected of course) and to click afterwards with some pixel of the place of this clicks

Func OCR_image_de_reference_pour_recolter($pixel_verification_haut_gauche_image,$image_de_reference,$largeur_image_de_reference_a_detecte,$longueur_image_de_reference_a_detecte);à completer ou changer

$pixel_verification_haut_gauche_image = PixelSearch(49, 48,973, 581,$color_image_haut_gauche)
    If Not @error Then

        For $coord_x_compteur = 0 To $largeur_image_de_reference_a_detecte - 1
            For $coord_y_compteur = 0 To $longueur_image_de_reference_a_detecte - 1
                If $image_de_reference[$coord_x_compteur][$coord_y_compteur] <> Hex(PixelGetColor($pixel_verification_haut_gauche_image[0],$pixel_verification_haut_gauche_image[1]), 6) Then
                    ExitLoop(2);mettre quelque chose d'autre pour dire que l'image n'a pas été trouvé et donc...
                    $pixel_verification_haut_gauche_image <> $pixel_haut_gauche_image
                Else
                    ContinueLoop
                EndIf
                $pixel_verification_haut_gauche_image[1] = $pixel_verification_haut_gauche_image[1] + 1
            Next
            $pixel_verification_haut_gauche_image[0] = $pixel_verification_haut_gauche_image[0] + 1
            $pixel_verification_haut_gauche_image[1] = $pixel_verification_haut_gauche_image[1] - $longueur_image_de_reference_a_detecte - 1
        Next
        
        MouseClick("left",$pixel_verification_haut_gauche_image[0],$pixel_verification_haut_gauche_image[1])
        Sleep(500)
        MouseClick("left",$pixel_verification_haut_gauche_image[0]+ 47,$pixel_verification_haut_gauche_image[1]+ 29)
        Sleep(500)
    Else
    
    $pixel_verification_haut_gauche_image <> $pixel_haut_gauche_image

    EndIf
    
EndFunc

Thus I would like to know if one can help me to finish the last function and 1st also if there are faults (I launched 2 scripts and there was no error).

Sorry for my english but I translated with my knowledge and Systran.

I already posted on the French site of AutoIt if there are French-speaking people: http://autoitscript.fr/forum/viewtopic.php?f=3&t=998

Link to comment
Share on other sites

  • 1 month later...

I made a new script:

Dim $TEST

Sleep(2000)
declaration_image_de_reference_("tesdttttt(re)",".BMP",$TEST, 200,150)

Sleep(2000)


If OCR_image_de_reference_(0x38425D,$TEST,200,150) = False Then
    MsgBox(0,"test","FALSE")
Elseif OCR_image_de_reference_(0x38425D,$TEST,200,150) = True Then
    MsgBox(0,"test","TRUE")
Endif

Func declaration_image_de_reference_($nom_de_image_reference,$format,$variable_ou_est_stockee_les_couleurs_image_reference, $largeur_image_de_reference,$longueur_image_de_reference);(mettre le nom de l'image qui se trouve dans le dossier @DesktopDir & "\Images pour le programme\", son format,la variable où seront stockées les couleurs, largeur de l'image, longueur de l'image)

Dim $coord_image_reference_x_haut_gauche_barre_text = 0 , $coord_image_reference_y_haut_gauche_barre_text = 0

    SplashImageOn("test",@DesktopDir & "\Images pour le programme\" & $nom_de_image_reference & $format,$largeur_image_de_reference,$longueur_image_de_reference,$coord_image_reference_x_haut_gauche_barre_text,$coord_image_reference_y_haut_gauche_barre_text );on doit avoir déjà créé un dossier sur le bureau se nommant "Images pour le programme" où il y aura l'image de réference
    Sleep(500)

Dim $variable_ou_est_stockee_les_couleurs_image_reference[$largeur_image_de_reference][$longueur_image_de_reference]

        For $coord_x_compteur = 0 To $largeur_image_de_reference - 1;-1 car le compteur $coord_x_compteur ne sera pas égal à 1 au début mais 0(=0,y)
            For $coord_y_compteur = 0 To $longueur_image_de_reference - 1;-1 car le compteur $coord_y_compteur ne sera pas égal à 1 au début mais 0(=x,0)
                $variable_ou_est_stockee_les_couleurs_image_reference[$coord_x_compteur][$coord_y_compteur] = Hex(PixelGetColor($coord_image_reference_x_haut_gauche_barre_text + 3,$coord_image_reference_y_haut_gauche_barre_text + 29), 6);+3 et +29 car il y a la barre de texte
                $coord_image_reference_y_haut_gauche_barre_text = $coord_image_reference_y_haut_gauche_barre_text + 1   
            Next
            $coord_image_reference_x_haut_gauche_barre_text += 1
            $coord_image_reference_y_haut_gauche_barre_text -= $longueur_image_de_reference
        Next
    
    Sleep(500)
    SplashOff()
    Sleep(500)
; >> 202,178
EndFunc

Func OCR_image_de_reference_($color_image_haut_gauche,$variable_ou_est_stockee_les_couleurs_image_reference,$largeur_image_de_reference_a_detecte,$longueur_image_de_reference_a_detecte);Couleur du 1er pixel,variable où sont stockées les couleurs de l'image de réference,largeur de cette image,longueur de cette image

Dim $variable_ou_est_stockee_les_couleurs_image_reference[$largeur_image_de_reference_a_detecte][$longueur_image_de_reference_a_detecte]
Dim $coord_x_compteur , $coord_y_compteur
Dim $color_verification_haut_gauche_image[$largeur_image_de_reference_a_detecte][$longueur_image_de_reference_a_detecte]

$pixel_verification_haut_gauche_image = PixelSearch(0,0 ,973, 581,$color_image_haut_gauche)
    If Not @error Then
        MsgBox(0,"PixelSearch","good")
        For $coord_x_compteur = 0 To $largeur_image_de_reference_a_detecte - 1;-1 car le compteur $coord_x_compteur ne sera pas égal à 1 au début mais 0
            For $coord_y_compteur = 0 To $longueur_image_de_reference_a_detecte - 1;-1 car le compteur $coord_y_compteur ne sera pas égal à 1 au début mais 0
                $color_verification_haut_gauche_image[$coord_x_compteur][$coord_y_compteur] = Hex(PixelGetColor($pixel_verification_haut_gauche_image[0],$pixel_verification_haut_gauche_image[1]), 6)
                If $variable_ou_est_stockee_les_couleurs_image_reference[$coord_x_compteur][$coord_y_compteur] <> Hex(PixelGetColor($pixel_verification_haut_gauche_image[0],$pixel_verification_haut_gauche_image[1]), 6) Then
                    MsgBox(0,"pixel","échec")
                    Return False
                EndIf
                MsgBox(0,"pixel","réussi")
                $pixel_verification_haut_gauche_image[1] += 1
            Next
            $pixel_verification_haut_gauche_image[0] += 1
            $pixel_verification_haut_gauche_image[1] -= $longueur_image_de_reference_a_detecte
        Next
        MsgBox(0,"Script","réussi")
        Return True
        
    Else
        MsgBox(0,"PixelSearch","bad")
        Return False
    
    EndIf
    
EndFunc

This script must record the color of each pixel of an image (that of SplashImageOn).

Then, it must seek the color of the 1st pixel of this image. Once found, it tests the colors of the pixels since that found to see whether they correspond with those of the image of reference.

My problem is that the image is not found whereas it is present. No error is posted.

I think that the error may come from -1 that there are or there aren't. Can you help me?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...