This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def preprocess(bgr_img):#gray image | |
img = bgr_img[:] | |
blur = cv2.GaussianBlur(img,(5,5),0) | |
ret,th_img = cv2.threshold(blur,0,255,cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU) #converts black to white and inverse | |
rows, cols = th_img.shape | |
bg_test = np.array([th_img[i][i] for i in range(5)]) | |
if bg_test.all() == 0: | |
text_color = 255 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def borders(here_img, thresh): | |
size = here_img.shape | |
check = int(115 * size[0] / 600) | |
image = here_img[:] | |
top, bottom = 0, size[0] - 1 | |
#plt.imshow(image) | |
#plt.show() | |
shape = size |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def segmentation(bordered, thresh): | |
try: | |
shape = bordered.shape | |
check = int(50 * shape[0] / 320) | |
image = bordered[:] | |
image = image[check:].T | |
shape = image.shape | |
#plt.imshow(image) | |
#plt.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def localize(main_image, gray_img, localized, bc, show): | |
#open the template as gray scale image | |
template = localized | |
#print(template.shape) | |
width, height = template.shape[::-1] #get the width and height | |
#match the template using cv2.matchTemplate | |
match = cv2.matchTemplate(gray_img, template, cv2.TM_CCOEFF_NORMED) | |
threshold = 0.8 | |
position = np.where(match >= threshold) #get the location of template in the image | |
for point in zip(*position[::-1]): #draw the rectangle around the matched template |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def detect_text(main_image, gray_img, localized, bc): | |
cimg = cv2.resize(localized, (30, 30)) | |
bordersize = 1 | |
nimg = cv2.copyMakeBorder(cimg, top=bordersize, bottom=bordersize, left=bordersize, right=bordersize, borderType=cv2.BORDER_CONSTANT, value=[255-bc, 0, 0]) | |
return main_image, nimg |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from preprocess import preprocess, detect_text, localize | |
from predictor import prediction | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import cv2 | |
def recognition(gray_image, show): | |
segments, template, th_img, text_color = preprocess(gray_image) | |
labels = [] | |
accuracy = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from keras.models import model_from_json | |
from keras.models import load_model | |
def prediction(img): | |
# load json and create model | |
json_file = open('cnn2\cnn2.json', 'r') | |
loaded_model_json = json_file.read() | |
json_file.close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
from recognition import recognition | |
import numpy as np | |
import time | |
import matplotlib.pyplot as plt | |
def camera(flag): | |
# choice = print("Click spacebar for photo and anything else for video.\n") | |
orig = 1 | |
cap = cv2.VideoCapture(0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from recognition import recognition | |
import cv2 | |
import matplotlib.pyplot as plt | |
from video_test import camera | |
import time | |
try: | |
test = input('Please enter the image directory with name.\n') | |
test = cv2.imread(test, 0) | |
plt.imshow(cv2.cvtColor(test, cv2.COLOR_GRAY2RGB)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def show(img, figsize=(10, 10)): | |
figure = plt.figure(figsize=figsize) | |
plt.imshow(img) | |
plt.xticks([]) | |
plt.yticks([]) | |
plt.show() | |
cap = cv2.VideoCapture(0) #run camera with device | |
imgs = [] #list to hold frames |
OlderNewer