Exemplo n.º 1
0
def fun2():
    imgdirname = ["data","img"]
    imgdirname = FileNameUtil.getDirname(FileNameUtil.getBasedirname(__file__),imgdirname)
    imgdirname = FileNameUtil.getPathJoin(imgdirname,"pic1.jpg")

    img = Image.open(imgdirname)

    plt.figure()
    plt.imshow(img)
    plt.title("ori")
    plt.show()

    pastImg = np.zeros([20,40],dtype=np.uint8)
    plt.figure()
    plt.imshow(pastImg)
    plt.title("past")
    plt.show()

    pastImg = Image.fromarray(pastImg)
    # left, upper, right, and lower pixel coordinate
    img.paste(pastImg,(40,0,80,20))
    plt.figure()
    plt.imshow(img)
    plt.title("after")
    plt.show()
Exemplo n.º 2
0
def testShowGasmeterArea():
    imgdirname = ["data", "img", "style0"]
    imgdirname = FileNameUtil.getDirname(FileNameUtil.getBasedirname(__file__),
                                         imgdirname)
    pattern = r'.*\.jpg$'
    filelist = FileNameUtil.getPathFilenameList(imgdirname, pattern)
    for each in filelist:
        ImageTool.showGasmeterArea(cv2.imread(each), filename=each)
Exemplo n.º 3
0
 def dataDirInit():
     path = FileNameUtil.getBasedirname(__file__)
     saveVariableDirname = FileNameUtil.getDirname(
         path, gps.saveVariableDirnameList)
     logDirname = FileNameUtil.getDirname(path, gps.logDirnameList)
     if not FileNameUtil.fileExisted(saveVariableDirname):
         os.makedirs(saveVariableDirname)
     if not FileNameUtil.fileExisted(logDirname):
         os.makedirs(logDirname)
Exemplo n.º 4
0
def testgetGasmeterAreaData():
    imgdirname = ["data", "img", "style0"]
    imgdirname = FileNameUtil.getDirname(FileNameUtil.getBasedirname(__file__),
                                         imgdirname)
    pattern = r'.*\.jpg$'
    filelist = FileNameUtil.getPathFilenameList(imgdirname, pattern)
    for each in filelist:
        img = ImageTool.getGasmeterAreaData(cv2.imread(each))
        data = np.array(img)
        print(data.shape)
        plt.figure()
        plt.title("gasmeter area")
        plt.imshow(img)
        plt.show()
Exemplo n.º 5
0
def getFilename(filename, baseDirname=None, dirnameList=None):
    """
    根据基目录、子目录名列表、文件名获取文件全路径名。
    如果基目录名为None,则基目录为当前文件所在目录。
    :param dirnameList:
    :param filename:
    :param baseDirname:
    """
    path = baseDirname
    if baseDirname is None:
        path = FileNameUtil.getBasedirname(__file__)

    if dirnameList is not None:
        path = FileNameUtil.getDirname(path, dirnameList)
    return FileNameUtil.getFilename(path, filename)
Exemplo n.º 6
0
def testGasmeterComposite():
    captchaCharacterLength = 5
    captchaBoxWidth = 128
    captchaBoxHeight = 64
    gen = GenDigitPicture(captchaCharacterLength,
                          captchaBoxWidth,
                          captchaBoxHeight,
                          backgroundColor=(1, 1, 1),
                          fontColor=(200, 200, 200))

    imgdirname = ["data", "img", "style0"]
    imgdirname = FileNameUtil.getDirname(FileNameUtil.getBasedirname(__file__),
                                         imgdirname)
    pattern = r'.*\.jpg$'

    filenames = FileNameUtil.getPathFilenameList(imgdirname, pattern)
    for filename in filenames:
        gasmeterPic = cv2.imread(filename)
        for i in range(5):
            text, image = gen.get_compose_gasmeter_text_and_image(gasmeterPic)
            print('begin ' + time.strftime("%Y-%m-%d %H:%M:%S") +
                  str(type(image)))
            f = plt.figure()
            ax = f.add_subplot(111)
            ax.text(0.1,
                    0.9,
                    text,
                    ha='center',
                    va='center',
                    transform=ax.transAxes)
            title = FileNameUtil.getFilenameFromFullFilepathname(
                filename) + " for composite"
            plt.title(title)
            plt.imshow(image)

            plt.show()
            print('end ' + time.strftime("%Y-%m-%d %H:%M:%S"))

            img = ImageTool.getGasmeterAreaData(
                cv2.cvtColor(image, cv2.COLOR_BGR2BGRA))
            plt.figure()
            title = title + ", found gasmeter area," + text
            plt.title(title)
            plt.imshow(img)
            plt.show()
Exemplo n.º 7
0
def testGet_compose_gasmeter_next_batch():
    imgdirname = ["data", "img", "style0"]
    imgdirname = FileNameUtil.getDirname(FileNameUtil.getBasedirname(__file__),
                                         imgdirname)
    pattern = r'.*\.jpg$'
    filelist = FileNameUtil.getPathFilenameList(imgdirname, pattern)

    captchaCharacterLength = 5
    captchaBoxWidth = 128
    captchaBoxHeight = 64
    gen = GenDigitPicture(captchaCharacterLength,
                          captchaBoxWidth,
                          captchaBoxHeight,
                          backgroundColor=(10, 10, 10),
                          fontColor=(200, 200, 200))

    for eachfile in filelist:

        gen.get_compose_gasmeter_next_batch(cv2.imread(eachfile))