Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Aniket025
GitHub Repository: Aniket025/Medical-Prescription-OCR
Path: blob/master/Model-3/ocr/helpers.py
426 views
1
# -*- coding: utf-8 -*-
2
"""
3
Helper functions for ocr project
4
"""
5
import matplotlib.pyplot as plt
6
import numpy as np
7
import cv2
8
9
SMALL_HEIGHT = 800
10
11
def implt(img, cmp=None, t=''):
12
""" Show image using plt """
13
plt.imshow(img, cmap=cmp)
14
plt.title(t)
15
plt.show()
16
17
18
def resize(img, height=SMALL_HEIGHT, allways=False):
19
""" Resize image to given height """
20
if (img.shape[0] > height or allways):
21
rat = 1.0*height / img.shape[0]
22
return cv2.resize(img, (int(rat*img.shape[1]), height), interpolation = cv2.INTER_CUBIC)
23
return img
24
25
26
def ratio(img, height=SMALL_HEIGHT):
27
""" Getting scale ratio """
28
return img.shape[0] / height
29
30
31
def extendImg(img, shape):
32
""" Extend 2D image (numpy array) in vertical and horizontal direction
33
Shape of result image will match 'shape'
34
Args:
35
img: image to be extended
36
shape: shape (touple) of result image
37
Returns:
38
Extended image
39
"""
40
x = np.zeros(shape, np.uint8)
41
x[:img.shape[0], :img.shape[1]] = img
42
return x
43
44