Jump to content

Pixel Pattern UDF


Zibit
 Share

Recommended Posts

Well i am working on my face recognizion program and i came up with this UDF. Im not going to release my FR program becouse it still has some issues to take care of. But this UDF might help some people.

There are only 2 function's.

_pixel_getpattern($pos1, $pos2, $len, [opt]$gui, [opt]ScreenMode)

_pixel_ratio($pattern, $pattern2, [opt]$ratio_level)

With _pixel_ratio you have to have 2 patterns to compare. and ratio level is 0-4

if it is 0 by default then it will return the result in pixel's that are the same in $pattern and $pattern2.

if you have ratio level higher than 0 then it will return a array. Look at example, You'll understand :blink:

UDF:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
Func _pixel_getpattern($pos1, $pos2, $len, $gui = "", $screen = 0)
    if $len > 50 Then 
        ConsoleWriteError("ERROR: Parameter lenght over limit ( 50 )" & @CRLF)
        SetError(500)
        Exit(500)
    EndIf
    if $len < 0 Then 
        ConsoleWriteError("ERROR: Parameter lenght under limit ( 0 )" & @CRLF)
        SetError(505)
        Exit(505)
    EndIf
    if $pos1 < 0 or $pos2 < 0 then 
        ConsoleWriteError("ERROR: Location cannot be under 0" & @CRLF)
        SetError(501)
        Exit(501)
    EndIf
    if $screen > 2 or $screen < 0 Then
        ConsoleWriteError("ERROR: Screen mode cannot be over 2 or smaller than 0!" & @CRLF)
        SetError(504)
        Exit(504)
        EndIf
    Opt("PixelCoordMode", $screen)
    Local $color[9999999]
    $i = 0
    $x = $pos1 - $len
    $y = $pos2 - $len
    $n = 0
    Do
    $n = $n + 1
    $color[$n] = PixelGetColor($x, $y, $gui)
    $y = $y + 1
    if $y = $pos2 + $len Then       
    $y = $pos2 - $len
    $i = $i + 1
    $x = $x + 1
    EndIf
    Until $i = $len*2 or $i > $len*2
    $color[0] = $n
    Return $color
EndFunc   ;==>Example1
Func _pixel_ratio($pattern, $pattern2, $confirm = 0)
if $confirm <> 0 then $confirm = $confirm
if $confirm > 10 Then 
ConsoleWriteError("ERROR: Too high confirm level! ( 10 max )" & @CRLF)
SetError(502)
Exit(502)
EndIf
Local $result[10]
$i = 0
$n = 0
Do
    $n = $n + 1
    if $pattern[$n] = $pattern2[$n] then $i = $i + 1
    Until $n = $pattern[0] or $n > $patter[0]
    $confirm_level = 0
    if Number(($i/$pattern[0])*100) > 70 then $confirm_level = 3
    if Number(($i/$pattern[0])*100) > 90 then $confirm_level = 4
    if Number(($i/$pattern[0])*100) < 50 then $confirm_level = 2
    if Number(($i/$pattern[0])*100) < 30 then $confirm_level = 1
$result[1] = $i
if $confirm > 1 Then $result[2] = $confirm_level
if $confirm > 2 Then $result[3] = Number(($i/$pattern[0])*100)
if $confirm > 3 Then $result[4] = $i & "/" & $pattern[0] & " Pixel's"
if $confirm = 0 Then $result = $i
Return $result
EndFunc

Example:

#include <pattern.au3>
$gui = GUICreate("Advanced Example", 124, 168, 900, 600)
GUISetState()
$pattern = _pixel_getpattern(50, 50, 20)
$bar = GUICtrlCreatePic("bar.jpg", 100, 100, 10, 0)
$status = GUICtrlCreateLabel("", 0, 10, 90, 100)
while 1
$pos = MouseGetPos()
$pattern2 = _pixel_getpattern($pos[0], $pos[1], 20)
$ratio = _pixel_ratio($pattern, $pattern2, 10)
GUICtrlSetPos($bar, 100, 100-$ratio[3], 10, $ratio[3])
GUICtrlSetData($status, "Correct: " & $ratio[1] & @CRLF & "Confirm Level: " & $ratio[2] & @CRLF & $ratio[3] & " %" & @CRLF & $ratio[4])
Sleep(1)
WEnd

Update 16. Sept

* Added Safety Protocols incase of Heavy CPU or RAM Consuption.

TESTED ON XP! MAY NOT WORK ON WIN 7 OR VISTA!

Edited by Zibit
Link to comment
Share on other sites

Sorry I don't get it after running your example. Can you elaborate more?

I ran it in W7, I see a small empty window, waited for a while and it posted some message.Posted Image

Correct: 0

Confirm level: 1

0%

0/1600 Pixe's

Edited by VAG
Link to comment
Share on other sites

  • 1 year later...

I know this is an old thread but I'd appreciate any help in getting the example working in the first post.

Or maybe someone can point me in the right direction.

I want to create a script which selects and captures a small portion of my screen, about 15 x 25 pixels, and compares it to one of about 60 stored (library) images of the same size, 15 x 25 pixels. When it finds a match, it returns a message.

I've read through a lot of threads in the last few days, but they all seem old and far more complex than what I need.

Thanks in advance for any suggestions.

taurus905

"Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs

Link to comment
Share on other sites

  • Moderators

taurus905,

Look at PixelChecksum in the Help file - that should get you started with your project. :)

If you run into problems, please open a new topic in the "General Help" section to prevent this thread getting taken off-topic. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hello Melba23,

Thank you for your advice and I appologize for the second part of my previous post which could have taken this thread off-topic.

To stay on-topic, I am still interested in any help to get the example working in the first post.

In particular, line 57 of the UDF reads:

Until $n = $pattern[0] or $n > $patter[0]

and should be either:

Until $n = $pattern[0] or $n > $pattern[0]

or

Until $n = $pattern[0] or $n > $pattern2[0]

My hope is that the original author, Zibit, sees this post and chimes in.

Thanks in advance for any help.

taurus905

"Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs

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...