def test_extract_digits5(self): try: extract_digits(03453) except TypeError: pass else: self.fail("Expected TypeError")
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')
import operator import sudukoSolver import cv2 as cv import joblib import numpy as np import sudoku_solver import utils img = cv.imread('imgs/sudoku7.png') img = cv.resize(img, (700, 700)) orig_img = img.copy() # img = cv.pyrUp(img) dilated = utils.basic_preprocess(img) # Contours contours = utils.find_contours(dilated) img, crop_rect = utils.draw_corners(dilated, contours) img = utils.find_grid(img, crop_rect) digits, numbers_descriptors, squares = utils.extract_digits(img, False) cv.imshow('img before', img) cv.imwrite('polished.jpg', img) board = utils.create_board_knn(digits, squares) # print(board) board_copy = np.array(board, 'int').reshape(9, 9) print(board_copy) to_solve = np.zeros(img.shape) board, to_solve, res = sudoku_solver.solve_sudoku(board, to_solve) print(board) cv.imshow('img', to_solve) cv.waitKey(0)
def test_extract_digits4(self): self.assertEqual(extract_digits("a0b3c4d5e3f"), "03453")
def test_extract_digits1(self): self.assertEqual(extract_digits("03453"), "03453")
def test_extract_digits0(self): self.assertEqual(extract_digits("ds03453fsdfs4506kgfdgdfg"), "034534506")