def get_result(file_name): image = cv2.imread(file_name) # 각각의 이미지를 chars변수에 담음 chars = utils.extract_chars(image) result_string = "" for char in chars: # 하나하나의 숫자 혹은 기호 matched = check(utils.resize20(char[1])) # 숫자 if matched < 10: result_string += str(int(matched)) continue # 기호 if matched == 10: matched = '+' elif matched == 11: matched = '-' elif matched == 12: matched = '*' result_string += matched return result_string
def get(self): """retorna as escolas para o editor""" try: key = request.headers.get('key') if key and API_KEY and key != API_KEY: return '', 401 query = {'status': 'ativo'} if request.args: nome_ou_eol = request.args.get('nome', None) if nome_ou_eol: if any(char.isdigit() for char in nome_ou_eol): eol = extract_digits(nome_ou_eol) query['_id'] = eol else: nome = extract_chars(nome_ou_eol) query['nome'] = { '$regex': nome.replace(' ', '.*'), '$options': 'i' } agrupamento = request.args.get('agrupamento', None) if agrupamento and agrupamento != 'TODOS': query['agrupamento'] = agrupamento tipo_atendimento = request.args.get('tipo_atendimento', None) if tipo_atendimento and tipo_atendimento != 'TODOS': query['tipo_atendimento'] = tipo_atendimento tipo_unidade = request.args.get('tipo_unidade', None) if tipo_unidade: query['tipo_unidade'] = { '$regex': tipo_unidade.replace(' ', '.*'), '$options': 'i' } page = int(request.args.get('page', 1)) limit = int(request.args.get('limit', 100)) total_documents = db.escolas.find(query).count() total_pages = math.ceil(total_documents / limit) if page > total_pages > 0: raise Exception('pagina nao existe') from_doc = (page * limit) - limit to_doc = page * limit if page * limit < total_documents else total_documents cursor = db.escolas.find(query).sort('_id', 1)[from_doc:to_doc] except Exception as exception: return app.response_class(json_util.dumps({'erro': str(exception)}), status=400, mimetype='application/json') else: return app.response_class(json_util.dumps([ cursor, { 'total_pages': total_pages, 'next': page + 1 if page < total_pages else None, 'previous': page - 1 if page > 1 else None } ]), status=200, mimetype='application/json')
def get_result(file_name): image = cv2.imread(file_name) chars = utils.extract_chars(image) result_string = "" for char in chars: matched = check(utils.resize20(char[1]), train, train_labels) if matched < 10: result_string += str(int(matched)) continue if matched == 10: matched = '+' elif matched == 11: matched = '-' elif matched == 12: matched = '*' result_string += matched return result_string
def get_result(file_name): image = cv2.imread(file_name) # 들어온 캐릭터를 왼쪽부터 각각의 이미지를 잘라 저장 chars = utils.extract_chars(image) result_str = '' for char in chars: # 이미지가 분류된 값 matched = check(utils.resize20(char[1]), train, train_labels) if matched < 10: result_str += str(int(matched)) continue if matched == 10: matched = '+' elif matched == 11: matched = '-' elif matched == 12: matched = '*' result_str += matched return result_str
def get_result(file_name): image = cv2.imread(file_name) chars = utils.extract_chars(image) result_string = "" # 문자를 저장할 변수 for char in chars: matched = check(utils.resize20(char[1]), train, train_labels) # char[1] : 하나하나의 숫자 이미지 array값. if matched < 10: # 숫자인 경우 result_string += str(int(matched)) continue # 숫자면 추가하고 다시 체크 반복. if matched == 10: matched = '+' elif matched == 11: matched = '-' elif matched == 12: matched = '*' result_string += matched return result_string
def get_result(file_name):# 파일이 들어오면 image = cv2.imread(file_name) chars = utils.extract_chars(image)# 각각의 이미지를 왼쪽부터 담고 result_string = "" for char in chars: # 이미지를 400으로 쭉 늘어트리고 매치되는 데이터를 담음 matched = check(utils.resize20(char[1]), train, train_labels) if matched < 10: # 숫자를 왼쪽부터 차례로 붙일 수 있게 result_string += str(int(matched)) continue if matched == 10: matched = "+" elif matched == 11: matched = "-" elif matched == 12: matched = "*" result_string += matched return result_string
import os import cv2 import utils # training_data 폴더 생성 및 그 내부에 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 폴더 생성 image = cv2.imread("images/3.png") chars = utils.extract_chars(image) for char in chars: cv2.imshow('Image', char[1]) input = cv2.waitKey(0) resized = cv2.resize(char[1], (20, 20)) if 48 <= input <= 57: # 0 ~ 9 name = str(input - 48) # os.walk는 하위의 폴더들을 탐색할 수 있게 해줍니다. (root, dirs, files) file_count = len(next(os.walk('./training_data/' + name + '/'))[2]) cv2.imwrite('./training_data/' + str(input - 48) + '/' + str(file_count + 1) + '.png', resized) elif input == ord('a') or input == ord('b') or input == ord('c'): # +, -, * name = str(input - ord('a') + 10) file_count = len(next(os.walk('./training_data/' + name + '/'))[2]) cv2.imwrite('./training_data/' + str(input - ord('a') + 10) + '/' + str(file_count + 1) + '.png', resized)
import os import cv2 import utils #training_data 폴더 생성 및 그 내부에 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 폴더 생성 image = cv2.imread('4.png') chars = utils.extract_chars(image) # 색깔별 숫자 추출 for char in chars: cv2.imshow('Image', char[1]) # 이미지 보여주고 input = cv2.waitKey(0) resized = cv2.resize(char[1], (20, 20)) # 크기 변경 # 사용자의 입력으로 라벨링함! if input >= 48 and input <= 57: name = str(input - 48) file_count = len(os.listdir('./training_data/' + name + '/')) # 파일 이름이 안 겹치게 만드는 것 1 2 3 4 이렇게 #사용자가 만들어준 디렉토리로 해당 데이터가 이동 #확장자 지정 꼭 하자! cv2.imwrite( './training_data/' + str(input - 48) + '/' + str(file_count + 1) + '.png', resized) print('./training_data/' + str(input - 48) + '/' + str(file_count + 1) + '.png') # 대문자 소문자 구분해서 누르기! elif input == ord('a') or input == ord('b') or input == ord( 'c'): #+ - * 경우는 (+,a), (-, b), (*, c)로 구분해서 만듬 name = str(input - ord('a') + 10) file_count = len(os.listdir('./training_data/' + name + '/')) cv2.imwrite(
import os import numpy as np import cv2 import utils # training_data 폴더 생성 및 그 내부에 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 폴더 생성 # 파이참에서 코드 돌려서 직접 레이블링 하는 과정 image = cv2.imread("4.png") chars = utils.extract_chars(image) # 이미지 내의 모든 숫자들을 추출 for char in chars: cv2.imshow('Image', char[1]) input = cv2.waitKey(0) resized = cv2.resize(char[1], (20, 20)) if input >= 48 and input <= 57: # 0~9 아스키코드 참고 name = str(input - 48) # 파일 이름 지정하기 file_count = len( next(os.walk('./training_data/' + name + '/'))[2] ) # ('./training_data/5/', [], ['4.png', '2.png', '3.png', '1.png']) -> 이런 식으로 반환됨. [2] 인덱스 값은 현재 디렉토리에 저장된 이미지들 cv2.imwrite('./training_data/' + str(input - 48) + '/' + str(file_count + 1) + '.png', resized) # 지정된 디렉토리에 이미지 저장 elif input == ord('a') or input == ord('b') or input == ord( 'c'): # + : a, - : b, x : c를 입력. ord('a') = 97. name = str(input - ord('a') + 10) # 차례대로 10, 11, 12에 들어감. file_count = len(next(os.walk('./training_data/' + name + '/'))[2]) cv2.imwrite( './training_data/' + name + '/' + str(file_count + 1) + '.png', resized)