|
@@ -64,26 +64,26 @@ def download(howhard, index):
|
|
if(r.status_code == 200):
|
|
if(r.status_code == 200):
|
|
with open(f'in/{howhard}_{index}.png', 'wb') as f:
|
|
with open(f'in/{howhard}_{index}.png', 'wb') as f:
|
|
f.write(r.content)
|
|
f.write(r.content)
|
|
- # We did not get a 200 Okay, log this... Hmm maybe we need to make a log file?
|
|
|
|
- print( f'{howhard}_{index}.png ' + str(r.status_code) )
|
|
|
|
|
|
+ else:
|
|
|
|
+ # We did not get a 200 Okay, log this... Hmm maybe we need to make a log file?
|
|
|
|
+ #print( f'{howhard}_{index}.png ' + str(r.status_code) )
|
|
|
|
+ raise ConnectionError('http://s0urce.io/client/img/word/{0}/{1} returned status_code {2}'.format(howhard, index, r.status_code))
|
|
|
|
|
|
-def img_point(x, y):
|
|
|
|
- global pix
|
|
|
|
|
|
+def img_point(pix, x, y):
|
|
"""
|
|
"""
|
|
img_point, returns a pixel of an image,
|
|
img_point, returns a pixel of an image,
|
|
given the x and y on the image.
|
|
given the x and y on the image.
|
|
"""
|
|
"""
|
|
return pix[x, y]
|
|
return pix[x, y]
|
|
|
|
|
|
-def img_avg(x, y):
|
|
|
|
- global im, pal
|
|
|
|
|
|
+def img_avg(im, pal, pix, x, y):
|
|
"""
|
|
"""
|
|
img_avg, returns the average brightness 0-255,
|
|
img_avg, returns the average brightness 0-255,
|
|
given the x and y on the image calls img_point,
|
|
given the x and y on the image calls img_point,
|
|
to get the individual rgb values to calculate,
|
|
to get the individual rgb values to calculate,
|
|
brightness.
|
|
brightness.
|
|
"""
|
|
"""
|
|
- rgb = img_point(x,y)
|
|
|
|
|
|
+ rgb = img_point(pix, x,y)
|
|
if(im.mode == 'P'):
|
|
if(im.mode == 'P'):
|
|
rgb = pal[rgb*3:(rgb+1)*3]
|
|
rgb = pal[rgb*3:(rgb+1)*3]
|
|
|
|
|
|
@@ -92,7 +92,7 @@ def img_avg(x, y):
|
|
|
|
|
|
return int( ( rgb[0] + rgb[1] + rgb[2] ) / 3 )
|
|
return int( ( rgb[0] + rgb[1] + rgb[2] ) / 3 )
|
|
|
|
|
|
-def is_set(x, y):
|
|
|
|
|
|
+def is_set(im, pal, pix, x, y):
|
|
global INTENSITY
|
|
global INTENSITY
|
|
"""
|
|
"""
|
|
is_set, returns True or False of calculating,
|
|
is_set, returns True or False of calculating,
|
|
@@ -105,11 +105,10 @@ def is_set(x, y):
|
|
False means the brightness at the given x and y,
|
|
False means the brightness at the given x and y,
|
|
is Greater Than which means its bright.
|
|
is Greater Than which means its bright.
|
|
"""
|
|
"""
|
|
- avg = img_avg(x,y)
|
|
|
|
|
|
+ avg = img_avg(im, pal, pix, x,y)
|
|
return (avg < INTENSITY)
|
|
return (avg < INTENSITY)
|
|
|
|
|
|
-def scan_img():
|
|
|
|
- global sx, sy, ex, ey, total
|
|
|
|
|
|
+def scan_img(im, pal, pix, size):
|
|
"""
|
|
"""
|
|
scan_img, looks at a image and looks for dark pixels,
|
|
scan_img, looks at a image and looks for dark pixels,
|
|
if it is a dark pixel record the number and resize the,
|
|
if it is a dark pixel record the number and resize the,
|
|
@@ -125,7 +124,7 @@ def scan_img():
|
|
|
|
|
|
for y in range( 0,size[1] ):
|
|
for y in range( 0,size[1] ):
|
|
for x in range( 0,size[0] ):
|
|
for x in range( 0,size[0] ):
|
|
- pnt_is = is_set(x,y)
|
|
|
|
|
|
+ pnt_is = is_set(im, pal, pix, x,y)
|
|
if (pnt_is):
|
|
if (pnt_is):
|
|
total += 1
|
|
total += 1
|
|
if x < sx:
|
|
if x < sx:
|
|
@@ -152,20 +151,22 @@ def scan_img():
|
|
#print (sx,ex,sy,ey)
|
|
#print (sx,ex,sy,ey)
|
|
return(sx,sy,ex,ey,total)
|
|
return(sx,sy,ex,ey,total)
|
|
|
|
|
|
-def save_image():
|
|
|
|
|
|
+def output_image(im, pal, pix, size):
|
|
"""
|
|
"""
|
|
For the size of the area we have reduced down to where the majority of dark pixels,
|
|
For the size of the area we have reduced down to where the majority of dark pixels,
|
|
are located, store all that into a list and return the list.
|
|
are located, store all that into a list and return the list.
|
|
|
|
|
|
- given start x, y and end x, y.
|
|
|
|
|
|
+ given image, palette, pixel for function passing.
|
|
returns multiple strings in a list that are edited to use characters to represent,
|
|
returns multiple strings in a list that are edited to use characters to represent,
|
|
the dark and light pixels of the image.
|
|
the dark and light pixels of the image.
|
|
"""
|
|
"""
|
|
result = []
|
|
result = []
|
|
|
|
+ ex = size[0]; sx = 0
|
|
|
|
+ ey = size[1]; sy = 0
|
|
for y in range(sy,ey):
|
|
for y in range(sy,ey):
|
|
s = ''
|
|
s = ''
|
|
for x in range(sx,ex):
|
|
for x in range(sx,ex):
|
|
- if is_set(x,y):
|
|
|
|
|
|
+ if is_set(im, pal, pix, x,y):
|
|
s += ON
|
|
s += ON
|
|
else:
|
|
else:
|
|
s += OFF
|
|
s += OFF
|
|
@@ -174,26 +175,21 @@ def save_image():
|
|
return result
|
|
return result
|
|
|
|
|
|
def run(difficult):
|
|
def run(difficult):
|
|
- global size, pix, im
|
|
|
|
"""
|
|
"""
|
|
run, represents a single execution of components to the image, (Actuall we do it 1 category at a time instead of just 1 single execution )
|
|
run, represents a single execution of components to the image, (Actuall we do it 1 category at a time instead of just 1 single execution )
|
|
those components do the following... (Each category has around 70 items so we standardize on 70, but )
|
|
those components do the following... (Each category has around 70 items so we standardize on 70, but )
|
|
(not all of the categories have 70 and thus we print a File does not exist)
|
|
(not all of the categories have 70 and thus we print a File does not exist)
|
|
We open and load the image, and get it's size,
|
|
We open and load the image, and get it's size,
|
|
then we scan_img for dark and light pixels, <-- This narrows the image down to just the majority of dark pixels
|
|
then we scan_img for dark and light pixels, <-- This narrows the image down to just the majority of dark pixels
|
|
- then from that we output the image line by line onto the screen after it has been save_image d into list form,
|
|
|
|
|
|
+ then from that we output the image line by line onto the screen after it has been output_image d into list form,
|
|
Where we ask the user what the word is, and after that we save all that to a file in the data directory.
|
|
Where we ask the user what the word is, and after that we save all that to a file in the data directory.
|
|
"""
|
|
"""
|
|
|
|
|
|
for x in range(0, 70):
|
|
for x in range(0, 70):
|
|
fname = f'in/{difficult}_{x}.png'
|
|
fname = f'in/{difficult}_{x}.png'
|
|
-
|
|
|
|
-# if os.path.exists() ... :(
|
|
|
|
- try:
|
|
|
|
- with open(fname, 'r') as f:
|
|
|
|
- f = f
|
|
|
|
- except FileNotFoundError:
|
|
|
|
- print("File does not exist")
|
|
|
|
|
|
+
|
|
|
|
+ if not os.path.exists(fname):
|
|
|
|
+ print("Could not find '{0}'".format(fname))
|
|
continue
|
|
continue
|
|
|
|
|
|
print(f"Loading: {fname}")
|
|
print(f"Loading: {fname}")
|
|
@@ -202,8 +198,7 @@ def run(difficult):
|
|
size = im.size
|
|
size = im.size
|
|
print(f"Size: {size[0]} x {size[1]}")
|
|
print(f"Size: {size[0]} x {size[1]}")
|
|
|
|
|
|
- if(im.mode == 'P'):
|
|
|
|
- pal = im.getpalette()
|
|
|
|
|
|
+ pal = im.getpalette()
|
|
|
|
|
|
sx = 0
|
|
sx = 0
|
|
ex = size[0]
|
|
ex = size[0]
|
|
@@ -211,17 +206,16 @@ def run(difficult):
|
|
ey = size[1]
|
|
ey = size[1]
|
|
total = 0
|
|
total = 0
|
|
|
|
|
|
- scan_img()
|
|
|
|
|
|
+ sx, sy, ex, ey, total = scan_img(im, pal, pix, size)
|
|
|
|
|
|
print(f"Chars within ({sx}, {sy}) - ({ex}, {ey}) total {total} pixels")
|
|
print(f"Chars within ({sx}, {sy}) - ({ex}, {ey}) total {total} pixels")
|
|
|
|
|
|
- img_s = save_image()
|
|
|
|
|
|
+ img_s = output_image(im, pal, pix, size)
|
|
for l in img_s:
|
|
for l in img_s:
|
|
print(l)
|
|
print(l)
|
|
- img_s.append(input('Word: '))
|
|
|
|
|
|
+ word = input('Word: ')
|
|
with open(f'{DIR}/{difficult}_{x}.txt', 'w') as f:
|
|
with open(f'{DIR}/{difficult}_{x}.txt', 'w') as f:
|
|
- for i_s in img_s:
|
|
|
|
- f.write(f'{i_s}\n')
|
|
|
|
|
|
+ f.write('{0}\n'.format(word))
|
|
|
|
|
|
print(f"Image saved to '{DIR}/{difficult}_{x}.txt' in byte string")
|
|
print(f"Image saved to '{DIR}/{difficult}_{x}.txt' in byte string")
|
|
# os.remove(f'{fname}') # Grr No bad bean, keep file for error checking
|
|
# os.remove(f'{fname}') # Grr No bad bean, keep file for error checking
|
|
@@ -233,19 +227,19 @@ if (DOWNLOAD == True):
|
|
print("EASY")
|
|
print("EASY")
|
|
# time.sleep(5)
|
|
# time.sleep(5)
|
|
for e in range(0, 62):
|
|
for e in range(0, 62):
|
|
- print(download('e', e))
|
|
|
|
|
|
+ download('e', e)
|
|
# time.sleep(random.randint(10, 15))
|
|
# time.sleep(random.randint(10, 15))
|
|
|
|
|
|
print("MEDIUM")
|
|
print("MEDIUM")
|
|
# time.sleep(5)
|
|
# time.sleep(5)
|
|
for m in range(0, 66):
|
|
for m in range(0, 66):
|
|
- print(download('m', m))
|
|
|
|
|
|
+ download('m', m)
|
|
# time.sleep(random.randint(10, 15))
|
|
# time.sleep(random.randint(10, 15))
|
|
|
|
|
|
print("HARD")
|
|
print("HARD")
|
|
# time.sleep(5)
|
|
# time.sleep(5)
|
|
for h in range(0, 55):
|
|
for h in range(0, 55):
|
|
- print(download('h', h))
|
|
|
|
|
|
+ download('h', h)
|
|
# time.sleep(random.randint(10, 15))
|
|
# time.sleep(random.randint(10, 15))
|
|
|
|
|
|
# Img Processing
|
|
# Img Processing
|
|
@@ -256,7 +250,7 @@ if (DOWNLOAD == True):
|
|
# ----------------------------------------------------------------------------------------
|
|
# ----------------------------------------------------------------------------------------
|
|
# All below was in a seperate dataJS.py file... but now I have fixed it so it's 1 script!
|
|
# All below was in a seperate dataJS.py file... but now I have fixed it so it's 1 script!
|
|
# Do we really need to worry about all this right now? (I think we have enough bugs to begin with.)
|
|
# Do we really need to worry about all this right now? (I think we have enough bugs to begin with.)
|
|
-
|
|
|
|
|
|
+JSONME = 'false' # Do not execute
|
|
if (JSONME.lower() != 'false'):
|
|
if (JSONME.lower() != 'false'):
|
|
print("Now exporting to JSON")
|
|
print("Now exporting to JSON")
|
|
print(f"Targeting file: '{JSONME}'")
|
|
print(f"Targeting file: '{JSONME}'")
|