def decorator(dct):
def wraper(func):
dct[func.__name__]=func
return wraper
class A():
mydict = dict()
@decorator(mydict)
def method1(self):
pass
@decorator(mydict)
def method2(self):
pass
a = A()
print(a.mydict)
def get(id):
... #важное уточнение функция достает из бд данные и возвращает словарь со всеми данными
list = ['a','b','c']
complete = []
for item in list:
complete.append(get(item))
print complete
import cv2
try:
from PIL import Image
except ImportError:
import Image
import pytesseract
import os
def get_points(approx, h, w):
x1 = max(min(r[0][0] for r in approx)-10,0)
y1 = max(min(r[0][1] for r in approx)-10,0)
x2 = min(max(r[0][0] for r in approx)+10,w)
y2 = min(max(r[0][1] for r in approx)+10,h)
return x1,y1,x2,y2
def filters(img):
imgray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
imgray = cv2.convertScaleAbs(imgray)
imgray = cv2.GaussianBlur(imgray, (7, 7), 0)
imgray = cv2.Canny(imgray, 10, 250)
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (25,25))
imgray = cv2.morphologyEx(imgray, cv2.MORPH_CLOSE, kernel)
return imgray
im = cv2.imread('doc3.jpg')
(h, w) = im.shape[:2]
imgray = filters(im)
cnts = cv2.findContours(imgray.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[0]
for ind, c in enumerate(reversed(cnts)):
peri = cv2.arcLength(c, True)
approx = cv2.approxPolyDP(c, 0.002 * peri, True)
x1,y1,x2,y2 = get_points(approx, h, w)
if pow((x2-x1)**2 + (y2-y1)**2, 0.5)<80:
continue
ROI = im[y1:y2, x1:x2]
#Далее отпарвка в тессеракт ROI