Morrison Posted October 15, 2011 Share Posted October 15, 2011 Hi, I´m still trying to find the middle in my Coord-Array! I try to find the "unique line" in the Type-Array. First the Y coord (colums) shall be searched for 999999. If found go on until 0 is found. Then half the count shall be set to 777777! And that for X and Y axis! The border pixel size should be 2, (if Type Pixelsize is 4 or 5 pix) and how to differ between long lines from short ones?!? Need some help, pls... expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> #include <ScreenCapture.au3> #include <WinAPI.au3> #include <File.au3> #include <Array.au3> Opt('MustDeclareVars', 1) Local $hBitmap, $hImage, $sImageType, $iX, $iY, $iXc, $iYc, $iMemo, $iPixelColor, $count, $File, $color1, $oForm, $color, $dc, $setpixel, $realesedc Local $hGraphic, $hBitmap, $hBackbuffer, $save, $hPen, $hWind Local $midY, $midX $File = FileOpen(@ScriptDir & "\coords.txt", 2) _Main() Func _Main() _GDIPlus_Startup() $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\PicA.jpg') $sImageType = _GDIPlus_EncodersGetCLSID("JPG") $iX = _GDIPlus_ImageGetWidth($hImage) $iY = _GDIPlus_ImageGetHeight($hImage) Local $aCoords[$iX][$iY] $oForm = GUICreate("GDI+", ($iX), ($iY)) GUISetBkColor(0xFFFFFF) GUISetState() $hWind = WinGetHandle($oForm) $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWind) $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iX, $iY, $hGraphic) $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsClear($hBackbuffer, 0xFFFFFFFF) For $iXc = 0 To $iX - 1 For $iYc = 0 To $iY - 1 $iPixelColor = Hex(_GDIPlus_GetPixel($hImage, $iXc, $iYc), 6) If Dec($iPixelColor) < Dec('882829') Then ;$count = $count + 1 FileWrite($File, $iXc & "," & $iYc & @CRLF) $aCoords[$iXc][$iYc] = 999999 SetPixel($oForm, $iXc, $iYc, $color) $hPen = _GDIPlus_PenCreate(0xFF000000); _GDIPlus_GraphicsDrawLine($hBackbuffer, $iXc, $iYc, $iXc + 1, $iYc + 1, $hPen) _GDIPlus_GraphicsDrawLine($hGraphic, $iXc, $iYc, $iXc + 1, $iYc + 1, $hPen) Else $aCoords[$iXc][$iYc] = 0 EndIf Next Next ;$save = _GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & '\Image1.jpg') Do Until GUIGetMsg() = $GUI_EVENT_CLOSE FileClose($File) _GDIPlus_Shutdown() ;~ For $iXc = 0 To $iX - 1 ;~ For $iYc = 0 To $iY - 1 ;~ If $aCoords[$iXc][$iYc] = 999999 Then ;~ For $iYc2 = $iYc To $iY - 1 ;~ If $aCoords[$iXc][$iYc2] = 0 Then ;~ $midY = ($iYc + Ceiling(Round(($iYc2 - $iYc) / 2) - 1)) ;~ For $iXc2 = $iXc To $iX - 1 ;~ If $aCoords[$iXc2][$iYc] = 0 Then ;~ $midX = ($iXc + Ceiling(Round(($iXc2 - $iXc) / 2) - 1)) ;~ $aCoords[$midX][$midY] = 777777 ;~ $iXc = $iXc2 ;~ ExitLoop ;~ EndIf ;~ Next ;~ $iYc = $iYc2 ;~ ExitLoop ;~ EndIf ;~ Next ;~ EndIf ;~ Next ;~ Next For $iXc = 0 To $iX - 1 For $iYc = 0 To $iY - 1 If $aCoords[$iXc][$iYc] = 999999 Then For $iYc2 = $iYc To $iY - 1 If $aCoords[$iXc][$iYc2] = 0 Then $aCoords[$iXc][$iYc + Ceiling(Round(($iYc2 - $iYc) / 2) - 1)] = 777777 ; eher rechts ausgerichtet $iYc = $iYc2 ExitLoop EndIf Next EndIf Next Next For $iYc = 0 To $iY - 1 For $iXc = 0 To $iX - 1 If $aCoords[$iXc][$iYc] = 999999 Then For $iXc2 = $iXc To $iX - 1 If $aCoords[$iXc2][$iYc] = 0 Then $aCoords[$iXc + Ceiling(Round(($iXc2 - $iXc) / 2) - 1)][$iYc] = 777777 ; eher rechts ausgerichtet $iXc = $iXc2 ExitLoop EndIf Next EndIf Next Next ; jede "zeile" durchgehen ;~ For $iXc = 0 To $iX - 1 ;~ For $iYc = 0 To $iY - 1 ;~ ; wenn schwarz "beginnt" ;~ If $aCoords[$iXc][$iYc] = 999999 Then ;~ ; gehe von dort aus ($iXc) weiter nach rechts, höchstens bis zum Ende des bildes. ;~ For $iYc2 = $iYc To $iY - 1 ;~ ; Wenn jetzt wieder eine weißer pixel kommt, ist die schwarze linie vorbei. ;~ If $aCoords[$iXc][$iYc2] = 0 Then ;~ ; Jetzt nur noch den Mittelpunkt der Linie ermitteln (Linie ist $iXc2 [rechter endpunkt] - $iXc [linker startpunkt] lang) ;~ ; Davon nehmen wir die Hälfte und addieren das auf den startpunkt der linie. ;~ ; bsp: Linie geht von 5 bis 14. Linie ist also 9 px lang (=14-5). Jede hälfte ist dann 4,5 px lang. ;~ ; Die Mitte liegt dann bei 9,5 (=5+4,5). Wobei wir natürlich runden müssen. ;~ ; $aCoords[$iYc][$iXc + Floor(($iXc2 - $iXc - 1) / 2)] = 777777 ; eher links ausgerichtet ;~ $aCoords[$iXc][$iYc + Ceiling(Round(($iYc2 - $iYc) / 2) - 1)] = 777777 ; eher rechts ausgerichtet ;~ $iYc = $iYc2 ;~ ExitLoop ;~ EndIf ;~ Next ;~ EndIf ;~ Next ;~ Next _ArrayDisplay($aCoords, Default, Default, 1) EndFunc ;==>_Main ; Gibt eine Zeile im Memo-Fenster aus Func MemoWrite($sMessage = '') GUICtrlSetData($iMemo, $sMessage & @CRLF, 1) EndFunc ;==>MemoWrite ; _GDIPlus_GetPixel Func _GDIPlus_GetPixel($hBitmap, $X, $Y) Local $result = DllCall($ghGDIPDLL, "int", "GdipBitmapGetPixel", "ptr", $hBitmap, "int", $X, "int", $Y, "dword*", 0) If @error Then Return SetError(1, 0, 0) Return SetError($result[0], 1, $result[4]) EndFunc ;==>_GDIPlus_GetPixel ;SetPixel Func SetPixel($oForm, $X, $Y, $color) $dc = DllCall("user32.dll", "int", "GetDC", "hwnd", $oForm) $setpixel = DllCall("gdi32.dll", "long", "SetPixel", "long", $dc[0], "long", $X, "long", $Y, "long", $color) $realesedc = DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "int", $dc[0]) EndFunc ;==>SetPixelfunc.au3 Link to comment Share on other sites More sharing options...
Morrison Posted October 16, 2011 Author Share Posted October 16, 2011 New Update: expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> #include <ScreenCapture.au3> #include <WinAPI.au3> #include <File.au3> #include <Array.au3> Opt('MustDeclareVars', 1) Local $hBitmap, $hImage, $sImageType, $iX, $iY, $iXc, $iYc, $iMemo, $iPixelColor, $count, $File, $color1, $oForm, $color, $dc, $setpixel, $realesedc Local $hGraphic, $hBitmap, $hBackbuffer, $save, $hPen, $hWind, $cPix, $line, $split, $split0, $split12, $split17, $split1, $split2, $split3, $fRand Local $midY[1] Local $midX[1] Local $found[1] $File = FileOpen(@ScriptDir & "\coords.txt", 2) $fRand = FileOpen(@ScriptDir & "\cRand.txt", 2) _Main() Func _Main() _GDIPlus_Startup() $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\Picaa.jpg') $sImageType = _GDIPlus_EncodersGetCLSID("JPG") $iX = _GDIPlus_ImageGetWidth($hImage) $iY = _GDIPlus_ImageGetHeight($hImage) Local $aCoords[$iX][$iY] $oForm = GUICreate("GDI+", ($iX), ($iY)) GUISetBkColor(0xFFFFFF) GUISetState() $hWind = WinGetHandle($oForm) $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWind) $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iX, $iY, $hGraphic) $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsClear($hBackbuffer, 0xFFFFFFFF) For $iXc = 0 To $iX - 1 For $iYc = 0 To $iY - 1 $iPixelColor = Hex(_GDIPlus_GetPixel($hImage, $iXc, $iYc), 6) If Dec($iPixelColor) < Dec('999999') Then ;$count = $count + 1 ;FileWrite($File, $iXc & "," & $iYc & @CRLF) $aCoords[$iXc][$iYc] = 999999 SetPixel($oForm, $iXc, $iYc, $color) $hPen = _GDIPlus_PenCreate(0xFF000000); _GDIPlus_GraphicsDrawLine($hBackbuffer, $iXc, $iYc, $iXc + 1, $iYc + 1, $hPen) _GDIPlus_GraphicsDrawLine($hGraphic, $iXc, $iYc, $iXc + 1, $iYc + 1, $hPen) Else $aCoords[$iXc][$iYc] = 0 EndIf Next Next ;$save = _GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & '\Image1.jpg') Do Until GUIGetMsg() = $GUI_EVENT_CLOSE ;FileClose($File) _GDIPlus_Shutdown() _ArrayDisplay($aCoords, Default, Default, 1) For $iXc = 0 To $iX - 1 For $iYc = 0 To $iY - 1 If $aCoords[$iXc][$iYc] = 999999 Then If $aCoords[$iXc - 1][$iYc] = 0 Or $aCoords[$iXc + 1][$iYc] = 0 Or $aCoords[$iXc][$iYc - 1] = 0 Or $aCoords[$iXc][$iYc + 1] = 0 Then $aCoords[$iXc][$iYc] = 777777 FileWrite($fRand, $iXc & "," & $iYc & @CRLF) EndIf EndIf Next Next FileClose($fRand) _ArrayDisplay($aCoords, Default, Default, 1) For $iXc = 0 To $iX - 1 For $iYc = 0 To $iY - 1 If $aCoords[$iXc][$iYc] = 777777 And $count = 0 Then $split17 = StringSplit($aCoords[$iXc][$iYc], ',', 1) $count = $count + 1 For $iYc2 = $iYc To $iY If $aCoords[$iXc][$iYc2] = 0 Then $split0 = StringSplit($aCoords[$iXc][$iYc2], ',', 1) $split1 = StringSplit($aCoords[$iXc][$iYc + 1], ',', 1) $split2 = StringSplit($aCoords[$iXc][$iYc2 - 1], ',', 1) $split3 = StringSplit($aCoords[$iXc][$iYc2 - 2], ',', 1) If $split17[1] <> $split2[1] Then $aCoords[$iXc][$iYc] = 0 $aCoords[$iXc][$iYc + 1] = 777777 $aCoords[$iXc][$iYc2 - 1] = 0 If $split3[1] = $split17[1] Then $aCoords[$iXc][$iYc2 - 2] = 777777 $iYc = $iYc2 ExitLoop EndIf EndIf EndIf Next EndIf $count = 0 Next Next For $iYc = 0 To $iY - 1 For $iXc = 0 To $iX - 1 If $aCoords[$iXc][$iYc] = 999999 Then ; If $aCoords[$iXc][$iYc] = 777777 And $count = 0 Then $count = $count + 1 $split17 = StringSplit($aCoords[$iXc][$iYc], ',', 1) For $iXc2 = $iXc To $iX If $aCoords[$iXc2][$iYc] = 0 Then $split0 = StringSplit($aCoords[$iXc2][$iYc], ',', 1) $split1 = StringSplit($aCoords[$iXc + 1][$iYc], ',', 1) $split2 = StringSplit($aCoords[$iXc2 - 1][$iYc], ',', 1) $split3 = StringSplit($aCoords[$iXc2 - 2][$iYc], ',', 1) If $split17[1] <> $split2[1] Then $aCoords[$iXc][$iYc] = 0 $aCoords[$iXc + 1][$iYc] = 777777 $aCoords[$iXc2 - 1][$iYc] = 0 If $split3[1] = $split17[1] Then $aCoords[$iXc2 - 2][$iYc] = 777777 $iXc = $iXc2 ExitLoop EndIf $iXc = $iXc2 ExitLoop EndIf EndIf Next EndIf EndIf $count = 0 Next Next _ArrayDisplay($aCoords, Default, Default, 1) For $iXc = 0 To $iX - 1 For $iYc = 0 To $iY - 1 If $aCoords[$iXc][$iYc] = 777777 Then For $iYc2 = $iYc To $iY - 1 If $aCoords[$iXc][$iYc2] = 0 Then If $aCoords[$iXc][$iYc + Ceiling(Round(($iYc2 - $iYc) / 2) - 1)] = 777777 Then $aCoords[$iXc][$iYc + Ceiling(Round(($iYc2 - $iYc) / 2) - 1)] = 777777 $iYc = $iYc2 ExitLoop Else $aCoords[$iXc][$iYc + Ceiling(Round(($iYc2 - $iYc) / 2) - 1)] = 111111 ; eher rechts ausgerichtet $iYc = $iYc2 ExitLoop EndIf EndIf Next EndIf Next Next For $iYc = 0 To $iY - 1 For $iXc = 0 To $iX - 1 If $aCoords[$iXc][$iYc] = 777777 Then For $iXc2 = $iXc To $iX - 1 If $aCoords[$iXc2][$iYc] = 0 Then If $aCoords[($iXc - 1) + Ceiling(Round(($iXc2 - $iXc) / 2))][$iYc] = 777777 Then $aCoords[($iXc - 1) + Ceiling(Round(($iXc2 - $iXc) / 2))][$iYc] = 777777 $iXc = $iXc2 ExitLoop Else $aCoords[($iXc - 1) + Ceiling(Round(($iXc2 - $iXc) / 2))][$iYc] = 222222 ; eher rechts ausgerichtet $iXc = $iXc2 ExitLoop EndIf EndIf Next EndIf Next Next _ArrayDisplay($aCoords, Default, Default, 1) For $iXc = 0 To $iX - 1 For $iYc = 0 To $iY - 1 If $aCoords[$iXc][$iYc] = 777777 Or $aCoords[$iXc][$iYc] = 999999 Then $aCoords[$iXc][$iYc] = 0 Else ;$aCoords[$iXc][$iYc] = 888888 EndIf Next Next For $iXc = 0 To $iX - 1 For $iYc = 0 To $iY - 1 If $aCoords[$iXc][$iYc] = 111111 Then For $iYc2 = $iYc To $iY - 1 If $aCoords[$iXc][$iYc2] = 0 Then $aCoords[$iXc][$iYc + Ceiling(Round(($iYc2 - $iYc) / 2))] = 111111 $iYc = $iYc2 ExitLoop ElseIf $aCoords[$iXc][$iYc2] = 111111 Then $aCoords[$iXc][$iYc2] = 0 EndIf Next EndIf Next Next For $iYc = 0 To $iY - 1 For $iXc = 0 To $iX - 1 If $aCoords[$iXc][$iYc] = 111111 Then For $iXc2 = $iXc To $iX - 1 If $aCoords[$iXc2][$iYc] = 0 Then $aCoords[$iXc + Ceiling(Round(($iXc2 - $iXc) / 2))][$iYc] = 111111 $iXc = $iXc2 ExitLoop ElseIf $aCoords[$iXc2][$iYc] = 111111 Then $aCoords[$iXc2][$iYc] = 0 EndIf Next EndIf Next Next _ArrayDisplay($aCoords, Default, Default, 1) For $iXc = 0 To $iX - 1 For $iYc = 0 To $iY - 1 If $aCoords[$iXc][$iYc] = 111111 Then FileWrite($File, $iXc & "," & $iYc & @CRLF) EndIf Next Next Dim $aRec If Not _FileReadToArray(@ScriptDir & "\cRand.txt", $aRec) Then MsgBox(4096, "Fehler", "Fehler beim Einlesen der Datei in das Array!" & @CRLF & "Fehlercode: " & @error) Exit EndIf For $x = 1 To $aRec[0] $split = StringSplit($aRec[$x], ',', 1) $aCoords[$split[1]][$split[2]] = 999999 ;MsgBox(0, 'Datensatz ' & $x & ':', $aRec[$x]) Next _ArrayDisplay($aCoords, Default, Default, 1) FileClose($File) EndFunc ;==>_Main ; Gibt eine Zeile im Memo-Fenster aus Func MemoWrite($sMessage = '') GUICtrlSetData($iMemo, $sMessage & @CRLF, 1) EndFunc ;==>MemoWrite ; _GDIPlus_GetPixel Func _GDIPlus_GetPixel($hBitmap, $x, $Y) Local $result = DllCall($ghGDIPDLL, "int", "GdipBitmapGetPixel", "ptr", $hBitmap, "int", $x, "int", $Y, "dword*", 0) If @error Then Return SetError(1, 0, 0) Return SetError($result[0], 1, $result[4]) EndFunc ;==>_GDIPlus_GetPixel ;SetPixel Func SetPixel($oForm, $x, $Y, $color) $dc = DllCall("user32.dll", "int", "GetDC", "hwnd", $oForm) $setpixel = DllCall("gdi32.dll", "long", "SetPixel", "long", $dc[0], "long", $x, "long", $Y, "long", $color) $realesedc = DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "int", $dc[0]) EndFunc ;==>SetPixel1anew.au3 Link to comment Share on other sites More sharing options...
UEZ Posted October 16, 2011 Share Posted October 16, 2011 What are you trying to do? Further can you upload also the additional files? Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Morrison Posted October 17, 2011 Author Share Posted October 17, 2011 (edited) I´ve got a lot of Fonts and now I´m trying to write a Font-recognizer and/or OCR. I want to collect information about the types of the fonts and I need the middle line to recognize the type. I tried to use "For to Next" to find 999999 and 0 and set 1st and last 999999 to 0 but it´s actually not finished. You need to edit "$hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\Picaa.jpg')" to $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\PicA.jpg') otherwise no File, no Array, huh Edited October 17, 2011 by Morrison Link to comment Share on other sites More sharing options...
UEZ Posted October 17, 2011 Share Posted October 17, 2011 What is the middle line in your example? Further you can convert the image to a 2 bit image and check for black and white pixels only. Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Morrison Posted October 17, 2011 Author Share Posted October 17, 2011 The middle line is the type for itself! Without pixelsize! Just the caracter Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now