1 Star 0 Fork 1

loic_wang / chinese_licence_plate_generator

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
world_generator.py 1.53 KB
一键复制 编辑 原始数据 按行查看 历史
nenger 提交于 2017-11-16 05:26 . No commit message
import itertools
import math
import os
import random
import sys
import numpy as np
import cv2
#get some random background image based on a opensource dataset
class WorldGenerator():
def __init__(self, img_dir, empty_dir, world_size):
self.output_shape = world_size
self.img_dir = img_dir
self.img_list = os.listdir(self.img_dir)
random.shuffle(self.img_list)
self.img_num = len(self.img_list)
#empty world
self.empty_world = cv2.imread(empty_dir + "blue.bmp")
self.empty_world = cv2.resize(self.empty_world, self.output_shape, interpolation = cv2.INTER_AREA)
#empth world means the background color is the same as the plate color
def generator_empty_world(self, color = 1):
return self.empty_world.copy()
def generate_one_world(self):
current_path = sys.path[0]
while True:
index = random.randint(0, self.img_num - 1)
fname = self.img_dir + self.img_list[index]
img = cv2.imread(fname, -1)
#we do not use one channnel image
if (len(img.shape) > 2 and img.shape[1] >= self.output_shape[0] and img.shape[0] >= self.output_shape[1]):
break
#get a roi with random position from the raw image
x = random.randint(0, img.shape[1] - self.output_shape[0])
y = random.randint(0, img.shape[0] - self.output_shape[1])
img = img[y:y + self.output_shape[1], x:x + self.output_shape[0]]
return img
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/loic_wang/chinese_licence_plate_generator.git
git@gitee.com:loic_wang/chinese_licence_plate_generator.git
loic_wang
chinese_licence_plate_generator
chinese_licence_plate_generator
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891