Exemplo n.º 1
0
def accuracy_calculate():
    # load mappings.txt
    dict1 = read_CSV(conf.MAPPINGS)
    dict2 = read_CSV(conf.TEST_MAPPINGS)

    # Calculate the accuracy.
    correct = 0
    for i in range(conf.TEST_NUMBER):
        if dict1[i] == dict2[i]:
            correct += 1
        else:
            print("Number:", i, "False:", dict1[i], "True:", dict2[i])
    print("Accuracy:", correct / conf.TEST_NUMBER)
    return correct / conf.TEST_NUMBER
Exemplo n.º 2
0
def cut_batch(start, end):
    num2char = read_CSV(conf.TRAIN_MAPPINGS)
    for i in range(start, end):
        name = str(i).zfill(4)
        path = conf.TRAIN_IMAGE_PATH+"/"+name+".jpg"
        image = cv2.imread(path, cv2.IMREAD_GRAYSCALE)
        cnt = 0
        cut_list = [image[:, 2:46], image[:, 37:81], image[:, 77:121], image[:, 117:161], image[:, 154:198]]
        for j in range(len(cut_list)):
            if not os.path.exists(conf.CUT_PATH+"/"+num2char[i][j]+"/"):
                os.makedirs(conf.CUT_PATH+"/"+num2char[i][j]+"/")
            path = conf.CUT_PATH+"/"+num2char[i][j]+"/"+name+"_"+str(j)+"_"+str(cnt)+".png"
            image = denoise_opencv.remove_noise(cut_list[j])
            cv2.imwrite(path, image)
        print(">> Cutting pictures:"+str(i+1)+"/"+str(end))
Exemplo n.º 3
0
def cut_batch(start, end):
    """ Batch processing. """
    mappings = read_CSV(conf.TRAIN_MAPPINGS)
    for i in range(start, end):
        name = str(i).zfill(4)
        image = cv2.imread(conf.DENOISE_PATH + "/" + name + ".png")
        horizontal_sum = np.sum(image, axis=0)
        sum = [item[0] for item in horizontal_sum]
        cut_list = image_cut(sum, image)

        for j in range(len(cut_list)):
            if not os.path.exists(conf.CUT_PATH + "/" +
                                  name_dic[mappings[i][j]] + "/"):
                os.makedirs(conf.CUT_PATH + "/" + name_dic[mappings[i][j]] +
                            "/")
            path = conf.CUT_PATH + "/" + name_dic[
                mappings[i][j]] + "/" + name + "_" + str(j) + ".png"
            cv2.imwrite(path, cut_list[j])
        print("Cutting pictures:" + str(i) + "/" + str(end - 1))
Exemplo n.º 4
0
from util import read_CSV
import conf

# load mappings.txt
dict1 = read_CSV(conf.MAPPINGS)
dict2 = read_CSV(conf.TEST_MAPPINGS)

# Calculate the accuracy.
correct = 0
for i in range(conf.TEST_NUMBER):
    if dict1[i] == dict2[i]:
        correct += 1
    else:
        print("Number:", i, "False:", dict1[i], "True:", dict2[i])
print("Accuracy:", correct / conf.TEST_NUMBER)
import random
import cv2
import tensorflow as tf
from util import read_CSV
import numpy as np
import conf
from multiprocessing import Process
import time
import os

num2idx = read_CSV(conf.TRAIN_MAPPINGS)


def get_positive_and_negative_batch(number):
    time1 = time.time()
    for i in range(60000):
        image1, image2, label = get_positive_pair()
        image_1 = np.concatenate([image1, image2], axis=1)
        save_path = conf.CUT_PATH + "/1/" + str(i) + "_" + str(number) + ".jpg"
        cv2.imwrite(save_path, image_1)

        image1, image2, label = get_negative_pair()
        image_2 = np.concatenate([image1, image2], axis=1)
        save_path = conf.CUT_PATH + "/0/" + str(i) + "_" + str(number) + ".jpg"
        cv2.imwrite(save_path, image_2)
        print("Cutting pictures:" + str(i + 1) + "/" + str(60000))
    else:
        time2 = time.time()
        print(str(time2 - time1) + "s")
    if not os.path.exists(conf.CUT_PATH + "/0/"):
        os.makedirs(conf.CUT_PATH + "/0/")
Exemplo n.º 6
0
import cv2
from util import read_CSV
import conf
import os
num2char = read_CSV(conf.TRAIN_MAPPINGS)


def cut_batch(start, end):
    for i in range(start, end):
        name = str(i).zfill(4)
        path = conf.TRAIN_IMAGE_PATH + "/" + name + ".jpg"
        image = cv2.imread(path, cv2.IMREAD_GRAYSCALE)
        cut_list = [
            image[:, 6:62], image[:, 53:109], image[:, 96:152], image[:,
                                                                      138:194]
        ]
        for j in range(4):
            if not os.path.exists(conf.CUT_PATH + "/" + num2char[i][j] + "/"):
                os.makedirs(conf.CUT_PATH + "/" + num2char[i][j] + "/")
            path = conf.CUT_PATH + "/" + num2char[i][
                j] + "/" + name + "_" + str(j) + ".png"
            if cut_list[j].shape == (80, 56):
                _, image = cv2.threshold(cut_list[j], 180, 255,
                                         cv2.THRESH_BINARY)
                cv2.imwrite(path, image)
        print("Cutting pictures:" + str(i) + "/" + str(end - 1))


if __name__ == '__main__':
    cut_batch(0, 10000)