Sign in to follow this  
Followers 0
gehenna

saving arrays

15 posts in this topic

so i am making this simple OCR thingie. its very simple as i don't need to be able to read different fonts. i don't even need to read all of the letters, just 20 different words or so. so i got the idea that instead of creating an OCR for each letter, i would create a sort of OWR (optical word recognition).

i would make a 2D array with the picture of the word i have. the array would of course have x, and y, as its two indexes and the values themselves would be the results of the get pixel color function at those two coordinates.

i would enclose the whole thing into two for loops and would thus be able to create my array.

when i would want to read the word, i would just compare the two arrays (aggain, closing them into two loops and checking if the same indexes have the same collors)

but what i would need for this is to have a database of arrays to compare to.

for that i was thinking of creating a 3D array where the first index would tell me which word this is, while the second and the third one would be the X, and Y coordinates (with the values of the pixel color function at the X, and Y coordinates)

in this case, all i would need to do is compare the word i am trying to read to this 3D array (sort of my word databse) and see which index comes out true.

the problem is, i would need to save this 3D array onto my hardrive. and i should be able to read from it and write onto it (updating new words)

so if there was a way to save an array to a file, any file, and then be able to load an array from that said file, that would be perfect. as i could create a temp array, load it, change what i need to, and then save it. so basicly updating it. but i would need the "save to", and "load from" commands for an array...can that be done?

or is there another solution perhaps?

thank you for your help

Share this post


Link to post
Share on other sites



or is there another solution perhaps?

I'd investigate storing the pix in a dbms that supports BLOB. Create the db, and then you just have a little au3 to query the table.


Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Share this post


Link to post
Share on other sites

i guess perhaps an alternative would be to use a program like photoshop to have the pictures of all the words in a certain order in one big picture. and then, at the start of the program, you would create your word database from that picture. that way, it would be storred in ram. but this is a very bad and slow solution. is there really no way of saving arrays?

Share this post


Link to post
Share on other sites

I'd investigate storing the pix in a dbms that supports BLOB. Create the db, and then you just have a little au3 to query the table.

it would probably be easier to create an au3 which would write all the elements of the array in the form:

$Array[1] = ...

$Array[2] = ...

$Array[3] = ...

$Array[4] = ...

$Array[5] = ...

so this would be a huge list defining all arrays at the beginning of your program...

considering they are two dimensional, the list would be very long :)

Share this post


Link to post
Share on other sites

gehenna,

Look at _FileReadToArray and _FileWriteFromArray in the Help file. However, they only deal with single dimension arrays, so you would have to play around with the array after loading and before saving to get it into a suitable format. Perhaps you could save the dimensions sequentially or format the data in suitably separated strings which could be split with StringSplit. There are other useful array functions in Array.au3 - details in the Help file again!

Be warned, heavy array manipulation can be slowish in AutoIt (depends on exactly what you do) - but if you limited it to just the beginning and end of the script the penalty might prove acceptable.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

gehenna,

Look at _FileReadToArray and _FileWriteFromArray in the Help file. However, they only deal with single dimension arrays, so you would have to play around with the array after loading and before saving to get it into a suitable format. Perhaps you could save the dimensions sequentially or format the data in suitably separated strings which could be split with StringSplit. There are other useful array functions in Array.au3 - details in the Help file again!

Be warned, heavy array manipulation can be slowish in AutoIt (depends on exactly what you do) - but if you limited it to just the beginning and end of the script the penalty might prove acceptable.

M23

so 1D arrays as elements of a 1D array (thus creating a 2D array) is a bad idea?

ow wait...so you mean for example that also comparing two arrays betwen themselves will be slow?

the comparing algorithm is simple. two for loops (as it is a 2D array) check with a simple if statement, if the $array1[j] = $array2[j] where the i and j are the counters of the two for loops.

Edited by gehenna

Share this post


Link to post
Share on other sites

so 1D arrays as elements of a 1D array (thus creating a 2D array) is a bad idea?

That statement is false. There is a difference between storing 1D arrays in an 1D array, and a 2D array.

Share this post


Link to post
Share on other sites

That statement is false. There is a difference between storing 1D arrays in an 1D array, and a 2D array.

is that only a java thing?

Share this post


Link to post
Share on other sites

gehenna,

Look at _FileReadToArray and _FileWriteFromArray in the Help file. However, they only deal with single dimension arrays, so you would have to play around with the array after loading and before saving to get it into a suitable format. Perhaps you could save the dimensions sequentially or format the data in suitably separated strings which could be split with StringSplit. There are other useful array functions in Array.au3 - details in the Help file again!

Be warned, heavy array manipulation can be slowish in AutoIt (depends on exactly what you do) - but if you limited it to just the beginning and end of the script the penalty might prove acceptable.

M23

this would have worked perfectly if only it was for 2D tables as well :)

Share this post


Link to post
Share on other sites

is that only a java thing?

No. That doesn't work in Java either. You must declare a 2D array, with two dimensions, for it to be a 2D array.

Any other method, such as placing 1D arrays in a 1D array, does not work.

Share this post


Link to post
Share on other sites

gehenna,

Here is an example of what I mean when I talk about saving 2D arrays in a 1D array:

#include <Array.au3>

Global $result[2][4]
Global $array[2] = ["1,2,3,4","a,b,c,d"]

For $i = 0 To UBound($array) - 1
    
    $temp = StringSplit($array[$i], ",")
    
    For $j = 1 To UBound($temp) - 1
        $result[$i][$j - 1] = $temp[$j]
    Next
Next

_ArrayDisplay($result)

Hope this gives you a better idea of what I meant.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

so i am making this simple OCR thingie. its very simple as i don't need to be able to read different fonts. i don't even need to read all of the letters, just 20 different words or so. so i got the idea that instead of creating an OCR for each letter, i would create a sort of OWR (optical word recognition).

i would make a 2D array with the picture of the word i have. the array would of course have x, and y, as its two indexes and the values themselves would be the results of the get pixel color function at those two coordinates.

i would enclose the whole thing into two for loops and would thus be able to create my array.

when i would want to read the word, i would just compare the two arrays (aggain, closing them into two loops and checking if the same indexes have the same collors)

but what i would need for this is to have a database of arrays to compare to.

for that i was thinking of creating a 3D array where the first index would tell me which word this is, while the second and the third one would be the X, and Y coordinates (with the values of the pixel color function at the X, and Y coordinates)

in this case, all i would need to do is compare the word i am trying to read to this 3D array (sort of my word databse) and see which index comes out true.

the problem is, i would need to save this 3D array onto my hardrive. and i should be able to read from it and write onto it (updating new words)

so if there was a way to save an array to a file, any file, and then be able to load an array from that said file, that would be perfect. as i could create a temp array, load it, change what i need to, and then save it. so basicly updating it. but i would need the "save to", and "load from" commands for an array...can that be done?

or is there another solution perhaps?

thank you for your help

#Include <Array.au3>

Dim $myArray[3][3]   


$myArray[0][0] = 00
$myArray[0][1] = 01
$myArray[0][2] = 02

$myArray[1][0] = 10
$myArray[1][1] = 11
$myArray[1][2] = 12

$myArray[2][0] = 20
$myArray[2][1] = 21
$myArray[2][2] = 22


_ArrayDisplay($myArray,"Save_Array")
Save_Array($myArray, "ArraySection" ,"ArrayFile.ini")



$myArray = Get_Array("ArraySection" ,"ArrayFile.ini")
_ArrayDisplay($myArray,"Get_Array")




Dim $myArray[3]
$myArray[0] = 0
$myArray[1] = 1
$myArray[2] = 2

_ArrayDisplay($myArray,"Save_Array")
Save_Array($myArray, "ArraySection2" ,"ArrayFile.ini")



$myArray = Get_Array("ArraySection2" ,"ArrayFile.ini")
_ArrayDisplay($myArray,"Get_Array")




Func Save_Array($Array , $Array_Section_Name ,$File_Name )
    
Local $rows = UBound($Array) , $cols = UBound($Array, 2) , $TXT = "" 

Select
Case $cols > 0
For $R = 0 To $rows - 1
For $C = 0 To $cols - 1
$TXT &= $R & "|" & $C & "=" &  StringToBinary($Array[$R][$C]) & @LF
Next
Next

Case $cols = 0
For $R = 0 To $rows - 1
$TXT &= $R & "|" & 0 & "=" &  StringToBinary($Array[$R]) & @LF
Next

EndSelect

IniWriteSection($File_Name, $Array_Section_Name , $TXT)
EndFunc





Func Get_Array($Array_Section_Name ,$File_Name)
    
Local $IniRead = IniReadSection($File_Name, $Array_Section_Name) _ 
, $Rows_And_Cols = $IniRead[$IniRead[0][0]][0] 

$Rows_And_Cols = StringSplit($Rows_And_Cols,"|")

if IsArray($IniRead) Then

Select

Case $Rows_And_Cols[0] > 0
Dim $Array[$Rows_And_Cols[1] + 1][$Rows_And_Cols[2] + 1]
For $i = 1 To $IniRead[0][0]
$Rows_And_Cols = StringSplit($IniRead[$i][0] ,"|")
$Array[$Rows_And_Cols[1]][$Rows_And_Cols[2]] = BinaryToString($IniRead[$i][1])
Next

Case $Rows_And_Cols[0] = 0
Dim $Array[$Rows_And_Cols[1] + 1]
For $i = 1 To $IniRead[0][0]
$Rows_And_Cols = StringSplit($IniRead[$i][0] ,"|")
$Array[$Rows_And_Cols[1]] = BinaryToString($IniRead[$i])
Next

EndSelect

Return $Array
Else
Return -1
EndIf
EndFunc

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

wow, thanks everybody :)

and for the 2D array 1D array part. im a freshman at computer science so i dont know much. but when we were doing java, i remember the guy telling us you can make a 2D array by using 1D arrays. in fact. java does not know more dimensional arrays, it only knows hot to nest 1D arrays, thus creating an illusion, that the arrays are more dimensional.

edit: found it

http://java.sun.com/docs/books/tutorial/ja...lts/arrays.html

this part: In the Java programming language, a multidimensional array is simply an array whose components are themselves arrays.

A consequence of this is that the rows are allowed to vary in length, as shown in the following MultiDimArrayDemo program....

Edited by gehenna

Share this post


Link to post
Share on other sites

http://java.sun.com/docs/books/tutorial/ja...lts/arrays.html

this part: In the Java programming language, a multidimensional array is simply an array whose components are themselves arrays.

A consequence of this is that the rows are allowed to vary in length, as shown in the following MultiDimArrayDemo program....

Ok, I understand what you mean now. In Java, 2D arrays are 1D arrays in an 1D array, but you still have to declare it as a two dimensional array.

Java allows arrays to be nested like this:

int[] a = {1};
int[] b = {4,5};
int[][] lol = {a,b};

But it doesn't actually allow something like this, which is how you would place a 1D array in a 1D array:

int[] a = {1};
int[] b = {4,5};
int[] c = {a,b};

This means that variable c would be an array holding two arrays. This works in AutoIt like so:

Dim $a[2] = [1,2]
Dim $b[2] = [3,4]
Dim $c[2] = [$a,$b]oÝ÷ ØÚ-zØZ·*.q©÷öÙèÁ§zË4ߧ±«p¡Ø¦z{"¢v¥jºÚÊ+b±©õ
ªëk(hاk¥¶*eyªëk+¢z-¶¬N¬zºè®Æ®¶­sdFÒb33c¶³%ÒÒ³Ã%ФFÒb33c¶%³%ÒÒ³2ÃEФFÒb33c¶5³%ÒÒ²b33c¶Âb33c¶%Ð ¤×6t&÷ÂgV÷C²gV÷C²Âb33c¶5³Õ³ÒoÝ÷ Ø­{-y§m+ºÚ"µÍ[H    ÌÍØVÌHHÌKB[H   ÌÍØÌHHÌË
B[H ÌÍØÖÌHHÉÌÍØK   ÌÍØBÌÍÙH  ÌÍØÖÌBÙÐÞ
    ][ÝÉ][ÝË    ÌÍÙÌJ

I hope that clears the issue...

Share this post


Link to post
Share on other sites

#Include <Array.au3>

Dim $myArray[3][3]   


$myArray[0][0] = 00
$myArray[0][1] = 01
$myArray[0][2] = 02

$myArray[1][0] = 10
$myArray[1][1] = 11
$myArray[1][2] = 12

$myArray[2][0] = 20
$myArray[2][1] = 21
$myArray[2][2] = 22


_ArrayDisplay($myArray,"Save_Array")
Save_Array($myArray, "ArraySection" ,"ArrayFile.ini")



$myArray = Get_Array("ArraySection" ,"ArrayFile.ini")
_ArrayDisplay($myArray,"Get_Array")




Dim $myArray[3]
$myArray[0] = 0
$myArray[1] = 1
$myArray[2] = 2

_ArrayDisplay($myArray,"Save_Array")
Save_Array($myArray, "ArraySection2" ,"ArrayFile.ini")



$myArray = Get_Array("ArraySection2" ,"ArrayFile.ini")
_ArrayDisplay($myArray,"Get_Array")




Func Save_Array($Array , $Array_Section_Name ,$File_Name )
    
Local $rows = UBound($Array) , $cols = UBound($Array, 2) , $TXT = "" 

Select
Case $cols > 0
For $R = 0 To $rows - 1
For $C = 0 To $cols - 1
$TXT &= $R & "|" & $C & "=" &  StringToBinary($Array[$R][$C]) & @LF
Next
Next

Case $cols = 0
For $R = 0 To $rows - 1
$TXT &= $R & "|" & 0 & "=" &  StringToBinary($Array[$R]) & @LF
Next

EndSelect

IniWriteSection($File_Name, $Array_Section_Name , $TXT)
EndFunc





Func Get_Array($Array_Section_Name ,$File_Name)
    
Local $IniRead = IniReadSection($File_Name, $Array_Section_Name) _ 
, $Rows_And_Cols = $IniRead[$IniRead[0][0]][0] 

$Rows_And_Cols = StringSplit($Rows_And_Cols,"|")

if IsArray($IniRead) Then

Select

Case $Rows_And_Cols[0] > 0
Dim $Array[$Rows_And_Cols[1] + 1][$Rows_And_Cols[2] + 1]
For $i = 1 To $IniRead[0][0]
$Rows_And_Cols = StringSplit($IniRead[$i][0] ,"|")
$Array[$Rows_And_Cols[1]][$Rows_And_Cols[2]] = BinaryToString($IniRead[$i][1])
Next

Case $Rows_And_Cols[0] = 0
Dim $Array[$Rows_And_Cols[1] + 1]
For $i = 1 To $IniRead[0][0]
$Rows_And_Cols = StringSplit($IniRead[$i][0] ,"|")
$Array[$Rows_And_Cols[1]] = BinaryToString($IniRead[$i])
Next

EndSelect

Return $Array
Else
Return -1
EndIf
EndFunc

ow my god, this works perfectl!!!!

i bow before thy

Share this post


Link to post
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
Sign in to follow this  
Followers 0