deprem-ocr-test / utils.py
mertcobanov's picture
Duplicate from deprem-ml/deprem-ocr
fde3eae
raw
history blame contribute delete
899 Bytes
import cv2
import csv
import json
from deta import Deta
import os
def preprocess_img(inp_image):
gray = cv2.cvtColor(inp_image, cv2.COLOR_BGR2GRAY)
gray_img = cv2.bitwise_not(gray)
return gray_img
def save_csv(mahalle, il, sokak, apartman):
adres_full = [mahalle, il, sokak, apartman]
with open("adress_book.csv", "a", encoding="utf-8") as f:
write = csv.writer(f)
write.writerow(adres_full)
return adres_full
def get_json(mahalle, il, sokak, apartman):
adres = {"mahalle": mahalle, "il": il, "sokak": sokak, "apartman": apartman}
dump = json.dumps(adres, indent=4, ensure_ascii=False)
return dump
def write_db(data_dict):
# 2) initialize with a project key
deta_key = os.getenv('DETA_KEY')
deta = Deta(deta_key)
# 3) create and use as many DBs as you want!
users = deta.Base("deprem-ocr")
users.insert(data_dict)