Commit 9c5b6043 by Owo Sugiana

Bug fixed relative path error

1 parent e03cbcec
from base64 import b64decode
import cv2
import numpy as np
def to_img(b64_str: str):
binary = b64decode(b64_str)
np_array = np.frombuffer(binary, np.uint8)
return cv2.imdecode(np_array, cv2.IMREAD_COLOR)
import sys
from base64 import b64encode
from cv2 import imwrite
from b64_image import to_img
img_file = sys.argv[1]
with open(img_file, 'rb') as f:
binary = f.read()
img_b64 = b64encode(binary)
img = to_img(img_b64)
imwrite('test.jpg', img)
opencv-python
jsonrpcclient
import sys
from pprint import pprint
from base64 import b64encode
from jsonrpcclient import request
import requests
from b64_image import to_img
img_file = sys.argv[1]
url = 'http://localhost:8000/rpc'
with open(img_file, 'rb') as f:
binary = f.read()
img_b64 = b64encode(binary)
p = dict(foto=img_b64.decode('utf-8'))
json_data = request('ocr_ktp', params=[p])
r = requests.post(url, json=json_data)
print(r.json())
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid_rpc.jsonrpc import jsonrpc_method
from b64_image import to_img
from ocr_ktp.ktp import ocr
@jsonrpc_method(endpoint='rpc')
def ocr_ktp(request, p):
img = to_img(p['foto'])
r = ocr(img)
if 'Tgl_Lahir' in r:
r['Tgl_Lahir'] = r['Tgl_Lahir'].strftime('%d-%m-%Y')
return r
with Configurator() as config:
config.include('pyramid_rpc.jsonrpc')
config.add_jsonrpc_endpoint('rpc', '/rpc')
config.scan(__name__)
app = config.make_wsgi_app()
port = 8000
server = make_server('0.0.0.0', port, app)
print('Listen web on port {}'.format(port))
server.serve_forever()
import os
from datetime import datetime
from string import (
ascii_letters,
......@@ -17,6 +18,8 @@ from jaccard_index.jaccard import jaccard_index
from . import ocr as base_ocr
THIS_DIR = os.path.split(__file__)[0]
LABELS = (
'NIK', 'Nama', 'Tempat/Tgl Lahir', 'Jenis', 'Alamat', 'RT/RW',
'Kel/Desa', 'Kecamatan', 'Agama', 'Status', 'Pekerjaan',
......@@ -69,7 +72,6 @@ def match_value(values, ref_values):
if j_index < 0.3:
continue
if last_j_index < j_index:
# print(f'Jaccard Index {value} vs {ref_value} = {j_index}')
last_j_index = j_index
found = ref_value
return found
......@@ -153,6 +155,7 @@ def parse(s):
def ocr(img, lang_dir='data'):
tess_opt = '--psm 6 --tessdata-dir ' + lang_dir
fullpath = os.path.join(THIS_DIR, lang_dir)
tess_opt = '--psm 6 --tessdata-dir ' + fullpath
s = base_ocr(img, 'ind', tess_opt)
return parse(s)
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!