Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- from src.library import *
- from libraries import OCR
- import Global as G
- from PIL import Image
- all_colors = ['white','orange','cyan','red','green','blue','yellow','purple','pink']
- target = search.Pixels()
- UpChars2 = OCR.loadfonts('UpChars2')
- UpChars = OCR.loadfonts('UpChars')
- ChatChars = OCR.loadfonts('ChatChars')
- MenuChars = OCR.loadfonts('MenuChars')
- '''
- .......... A lot of missing shit here ...........
- ......
- ...
- '''
- #Bool / Rect
- def __extractTextRect(box, colors):
- ''' I down scale the image for faster rect extraction,
- Then I upscale the found rects again.
- '''
- scale = 0.7
- size = (box[2]-box[0]), (box[3]-box[1])
- points = list()
- for cl in colors:
- points += target.find(cl, box, 2)
- if not points: return False
- im = Image.new('RGB', size, 0)
- pix = im.load()
- for pt in points:
- x,y = (pt[0]-box[0]), (pt[1]-box[1])
- pix[x,y] = (255,255,255)
- W = int(round(size[0]*scale))
- H = int(round(size[1]*scale))
- im = im.resize((W,H), Image.NEAREST)
- target.set_target(im)
- colors = target.find((255,255,255), [0,0,W,H], 0)
- target.set_target(None)
- if colors:
- clusters = pointtools.group_ex(colors, 9,1)
- rects = list()
- for pts in clusters:
- (x1,y1,x2,y2) = pointtools.bounds(pts)
- x1 /= scale; y1 /= scale
- x2 /= scale; y2 /= scale
- W,H = (x2-x1), (y2-y1)
- if W > 7 and H > 7:
- rects.append((round(box[0]+x1)-4, round(box[1]+y1)-1,
- round(box[0]+x2)+4, round(box[1]+y2)+1))
- return rects, points
- return False
- #Bool / String
- def rs07_isScreenText(text, box=G.SCAPE['MAIN'], colors=[(255,255,0)]):
- data = __extractTextRect(box, colors)
- if not data: return False
- rectangles, points = data
- if rectangles:
- strings = list()
- im = Image.new('RGB', box[2:4], 0)
- pix = im.load()
- for pt in points:
- pix[pt[0], pt[1]] = (255,255,255)
- for rect in rectangles:
- rect = [int(round(x)) for x in rect]
- string = OCR.imageToString2(im.crop(rect), UpChars2, ['white'], 5)
- strings.append(string)
- if strings:
- if isinstance(text, str):
- for haystack in strings:
- if text in haystack.lower():
- return haystack
- else:
- for haystack in strings:
- for part in text:
- if part in haystack.lower():
- return haystack
- return False
- def rs07_getScreenText(box=G.SCAPE['MAIN'], colors=[(255,255,0)]):
- data = __extractTextRect(box, colors)
- if not data: return False
- rectangles, points = data
- if rectangles:
- strings = list()
- im = Image.new('RGB', box[2:4], 0)
- pix = im.load()
- for pt in points:
- pix[pt[0], pt[1]] = (255,255,255)
- for rect in rectangles:
- rect = [int(round(x)) for x in rect]
- string = OCR.imageToString2(im.crop(rect), UpChars2, ['white'], 5)
- strings.append(string)
- return strings
- return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement