본문 바로가기
전체보기/Python

임시저장

by 피망우유 2020. 1. 8.

http://blog.naver.com/kjpark79/220787920384

 

 

# make data using font

import glob
import io
import os
import random
import cv2
import csv

import numpy
from PIL import Image, ImageFont, ImageDraw
from scipy.ndimage.interpolation import map_coordinates
from scipy.ndimage.filters import gaussian_filter

SCRIPT_PATH = 'D:/conda_env/tensorflow-hangul-recognition-master'

# Default data paths.
label_file = SCRIPT_PATH + '/labels/2350-common-hangul.txt'
DEFAULT_FONTS_DIR = os.path.join(SCRIPT_PATH, '../fonts')
DEFAULT_OUTPUT_DIR = os.path.join(SCRIPT_PATH, '../image-data')

labels_csv = SCRIPT_PATH + '/image-data/labels-map.csv'

# Number of random distortion images to generate per font and character.
DISTORTION_COUNT = 3

# Width and height of the resulting image.
IMAGE_WIDTH = 64
IMAGE_HEIGHT = 64

labels_csv = io.open(labels_csv, 'r', encoding='utf-8')
labels_file = io.open(label_file, 'r', encoding='utf-8').read().splitlines()
rdr = csv.reader(labels_csv)
for line in rdr:
    print(line[0])
    img = cv2.imread(line[0])  # was empty???
    img_name = line[0].split('\\')[-1]
    img_name = img_name.split('.')[0]
    if not(os.path.isdir(SCRIPT_PATH + '/' + line[1])):
        os.makedirs(os.path.join(SCRIPT_PATH + '/' + line[1]))
    #print(SCRIPT_PATH + '/' + line[1] + '/' + img_name + '.png')
    cv2.imwrite(SCRIPT_PATH + '/' + line[1] + '/' + img_name + '.png', img)
labels_csv.close()

'전체보기 > Python' 카테고리의 다른 글

[Tkinter] Python 폴더 선택 창 생성  (1) 2020.04.30
[tkinter + OpenCV] Python 비디오 재생 GUI 생성  (2) 2020.02.29
pytesseract 에러 + tesseract-ocr-kor  (0) 2020.02.10
파이썬 GUI  (0) 2019.12.02

댓글