Jump to content



Photo

Pixel Pattern UDF


  • Please log in to reply
9 replies to this topic

#1 Zibit

Zibit

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 262 posts

Posted 23 July 2010 - 06:05 AM

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:
AutoIt         
#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, 16 September 2010 - 08:41 AM.








#2 VAG

VAG

    Wayfarer

  • Active Members
  • Pip
  • 57 posts

Posted 23 July 2010 - 06:30 AM

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, 23 July 2010 - 06:32 AM.


#3 Zibit

Zibit

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 262 posts

Posted 23 July 2010 - 08:37 AM

why didnt you check the script O.o ??? move the mouse up to left corner of ur screen then youll get it.

#4 VAG

VAG

    Wayfarer

  • Active Members
  • Pip
  • 57 posts

Posted 23 July 2010 - 09:17 AM

I did look throught the script.
FYI, It works in XP, but not working in my Win7 Ultimate system.

#5 Zibit

Zibit

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 262 posts

Posted 23 July 2010 - 01:05 PM

well ok ill post that it wouldnt work on win 7. btw thx for telling me :blink:

#6 JohnOne

JohnOne

    John

  • Active Members
  • PipPipPipPipPipPip
  • 8,871 posts

Posted 23 July 2010 - 06:11 PM

It works fine on my win 7, but it is really heavy on CPU.
AutoIt Absolute Beginners Require a serial
Run('hh mk:@MSITStore:'&StringReplace(@AutoItExe,'.exe','.chm')&'::/html/tutorials/helloworld/helloworld.htm','',@SW_MAXIMIZE)

#7 taurus905

taurus905

    "Lead, follow, or get out of the way."

  • Active Members
  • PipPipPipPipPipPip
  • 440 posts

Posted 11 February 2012 - 09:47 AM

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

#8 Lakes

Lakes

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 761 posts

Posted 11 February 2012 - 10:11 AM

Could this track the mouse pointer in a youtube video?

I have an idea to remake a youtube video tutorial but in 720p quality.

#9 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,393 posts

Posted 11 February 2012 - 10:30 AM

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
StringSize - Automatically size controls to fit text - ExtMsgBox - A user customisable replacement for MsgBox

Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs

Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames

GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes

ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display

RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options

GUIListViewEx - Insert, delete, move, drag and sort ListView items


#10 taurus905

taurus905

    "Lead, follow, or get out of the way."

  • Active Members
  • PipPipPipPipPipPip
  • 440 posts

Posted 11 February 2012 - 10:37 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users