Beispiel #1
0
 def genIDDen(self):
     ### PARAMETERS
     self.buildCommonParams()
     idheight = int(
         self.p.new('height-scale', 0.5, paramrange=(0.3, 0.8),
                    freeze=True).x * self.height)
     idangle = self.p.new('angle', 0, paramrange=(-5, 5), freeze=True).x
     raio_id_gui = self.p.new('idblack_raio_id_gui',
                              1.2,
                              paramrange=(1.0, 1.8)).x
     ### LAYERS
     lGuiBgSo = self.buildGuillocheBGSo(idheight, idangle)
     txt = self.idnumbergen.gen()
     lId = self.buildID(txt, int(idheight * raio_id_gui), idangle, 1.1)
     lOtherLine = self.buildOtherLines(idangle)
     lGuiBG = self.buildGuillocheBG()
     l_bg = Layer(alpha=255 * np.ones((self.height, self.width), 'uint8'),
                  color=self.bg_col)
     ### EFFECTS
     lGuiBG.alpha = random.uniform(0.4, 0.95) * lGuiBG.alpha
     lOtherLine.alpha = random.uniform(0.4, 0.95) * lOtherLine.alpha
     lId.alpha = self.si.inkeffect(lId.alpha)
     lId.alpha = self.si.matnet(lId.alpha)
     lId.alpha = self.si.sonhoe(lId.alpha)
     lId.alpha = self.si.blur(lId.alpha)
     lGuiBgSo.alpha = self.si.matnet(lGuiBgSo.alpha)
     lGuiBgSo.alpha = self.si.blur(lGuiBgSo.alpha)
     ### MERGES
     layers = [lId, lGuiBgSo, lOtherLine, lGuiBG, l_bg]
     blends = ['normal'] * len(layers)
     idline = self.colorize.merge_down(layers, blends).color
     idline = self.si.addnoise(idline)
     idline = self.si.heterogeneous(idline)
     idline = self.si.colorBlob(idline)
     return idline, txt
Beispiel #2
0
    def buildGuillocheBGSo(self, height, angel):
        alpha = np.zeros((self.height, self.width), 'uint8')
        dy = height * 1.0 / 5
        x0 = self.x0
        y0 = self.y0 - height / 2
        amp = self.p.new('gui_amp', dy / 2, freeze=True).x
        wavelength = self.p.new('wavelength', dy * 4, freeze=True).x
        length = self.p.new('length',
                            self.height * 7,
                            paramrange=(self.height * 5, self.height * 9),
                            freeze=True).x
        phase = random.randint(0, 360)
        thick = random.randint(1, 2)
        for i in range(6):
            pts = self.sineWave(x0,
                                int(i * dy + y0),
                                length,
                                amp,
                                wavelength,
                                phase=phase)
            cv2.polylines(alpha, [pts],
                          isClosed=False,
                          color=255,
                          thickness=thick)
        rotM = cv2.getRotationMatrix2D((x0, y0), angel, 1)
        alpha = cv2.warpAffine(alpha, rotM, (alpha.shape[1], alpha.shape[0]))

        return Layer(alpha=alpha, color=self.sodo_col)
Beispiel #3
0
 def genDOB(self):
     ### PARAMETERS
     self.buildCommonParams()
     nameheight = int(
         self.p.new(
             'dobval_height-scale', 0.5, paramrange=(0.3, 0.8),
             freeze=True).x * self.height)
     namekeyheight = int(
         self.p.new(
             'dobkey_height-scale', 0.5, paramrange=(0.3, 0.8),
             freeze=True).x * self.height)
     nameangle = self.p.new('angle', 0, paramrange=(-5, 5)).x
     ### LAYERS
     txt = self.dobgen.gen()
     lnamekey = self.buildDOBKey(namekeyheight, nameangle)
     lnameval = self.buildDOB(txt, nameheight, nameangle)
     lGuiBG = self.buildGuillocheBG()
     l_bg = Layer(alpha=255 * np.ones((self.height, self.width), 'uint8'),
                  color=self.bg_col)
     ### EFFECTS
     lGuiBG.alpha = random.uniform(0.4, 0.95) * lGuiBG.alpha
     lnamekey.alpha = random.uniform(0.4, 0.95) * lnamekey.alpha
     lnameval.alpha = self.si.inkeffect(lnameval.alpha)
     lnameval.alpha = self.si.matnet(lnameval.alpha)
     lnameval.alpha = self.si.sonhoe(lnameval.alpha)
     lnameval.alpha = self.si.blur(lnameval.alpha)
     ### MERGES
     layers = [lnameval, lnamekey, lGuiBG, l_bg]
     blends = ['normal'] * len(layers)
     nameline = self.colorize.merge_down(layers, blends).color
     nameline = self.si.addnoise(nameline)
     nameline = self.si.heterogeneous(nameline)
     nameline = self.si.colorBlob(nameline)
     return nameline, txt
Beispiel #4
0
    def buildOtherLines(self, angle):
        mask, txt = self.renderer.toMask2(self.keyfonts.genByName('arial'),
                                          txt='CHUNG MINH NHAN DAN')
        #move mask
        #TODO randomize
        adapted_mask = self.putMask(
            mask, (self.height / 2, self.width / 2, -self.height / 4, angle))

        return Layer(alpha=adapted_mask, color=self.sodo_col)
Beispiel #5
0
 def buildID(self, txt, height, angel, p_den=1.1):
     if np.random.rand() < p_den:
         afont = self.idfonts.genByName('UTM Helve.ttf')
         temp = self.p.new('idblack_s2h', 1.0).x
         afont.s2h = (temp, temp)
         temp = self.p.new('idblack_w2h', 1.0).x
         afont.w2h = (temp, temp)
         col = self.text_col
     else:
         afont = self.idfonts.genByName('9thyssen')
         temp = self.p.new('s2h', 1.0, freeze=True).x
         afont.s2h = (temp, temp)
         temp = self.p.new('w2h', 1.0, freeze=True).x
         afont.w2h = (temp, temp)
         col = self.sodo_col
     mask, txt = self.renderer.toMask2(afont, txt=txt)
     adapted_mask = self.putMask(mask, (height, self.x0, self.y0, angel))
     return Layer(alpha=adapted_mask, color=col)
Beispiel #6
0
 def buildDOBKey(self, height, angel):
     x0 = int(
         self.p.new('dobkey_x0',
                    self.width / 2,
                    paramrange=(0, self.width),
                    freeze=True).x)
     y0 = int(
         self.p.new('dobkey_y0',
                    self.height / 2,
                    paramrange=(0, self.height),
                    freeze=True).x)
     txt = 'Sinh ngày:' + '.' * 80
     afont = self.keyfonts.genByName('arial')
     temp = self.p.new('kelltype_s2h', 1.0, freeze=True).x
     afont.s2h = (temp, temp)
     temp = self.p.new('kelltype_w2h', 1.0, freeze=True).x
     afont.w2h = (temp, temp)
     mask, txt = self.renderer.toMask2(afont, txt=txt)
     adapted_mask = self.putMask(mask, (height, x0, y0, angel))
     return Layer(alpha=adapted_mask, color=self.text_col)
Beispiel #7
0
 def buildName(self, txt, height, angel):
     x0 = int(
         self.p.new('nameval_x0',
                    self.width / 2,
                    paramrange=(0, self.width),
                    freeze=True).x)
     y0 = int(
         self.p.new('nameval_y0',
                    self.height / 2,
                    paramrange=(0, self.height),
                    freeze=True).x)
     afont = self.valuefonts.genByName(
         'traveling')  #Kingthings,Olivetti, traveling, pala.ttf, palab.ttf
     temp = self.p.new('nametype_s2h', 1.0, freeze=True).x
     afont.s2h = (temp, temp)
     temp = self.p.new('nametype_w2h', 1.0, freeze=True).x
     afont.w2h = (temp, temp)
     mask, txt = self.renderer.toMask2(afont, txt=txt)
     #move mask
     adapted_mask = self.putMask(mask, (height, x0, y0, angel))
     return Layer(alpha=adapted_mask, color=self.text_col)
Beispiel #8
0
    def buildGuillocheBG(self):
        alpha = np.zeros((self.height, self.width), 'uint8')
        amp = random.randint(self.height / 7, self.height / 5)
        wavelength = random.randint(self.height / 4, self.height / 2)
        thick = random.randint(1, 2)
        angle = random.uniform(0.0, 160.0)
        n = random.randint(15, 30)
        y0 = random.randint(20, 30)
        dy = (self.height - y0) / n
        x0 = random.randint(20, 30)
        dx = (self.width - x0) / n

        for i in range(n):
            x0 += dx + random.randint(-2, 2)
            y0 += dy + random.randint(-2, 2)
            pts = self.sineWave(x0, y0, int(self.width * 0.8), amp, wavelength,
                                angle)
            cv2.polylines(alpha, [pts],
                          isClosed=False,
                          color=255,
                          thickness=thick)

        return Layer(alpha=alpha, color=self.guilloche_col)
Beispiel #9
0
 def buildDOB(self, txt, height, angel, p_chuin=0.3):
     x0 = int(
         self.p.new('dobval_x0',
                    self.width / 2,
                    paramrange=(0, self.width),
                    freeze=True).x)
     y0 = int(
         self.p.new('dobval_y0',
                    self.height / 2,
                    paramrange=(0, self.height),
                    freeze=True).x)
     p = np.random.rand()
     #         if p < (1 - p_chuin)/2:
     #             afont = self.valuefonts.genByName('Olivetti') #Kingthings,Olivetti, pala.ttf, palab.ttf
     #             temp = self.p.new('dob_olivette_s2h', 1.0, freeze=True).x
     #             afont.s2h = (temp,temp)
     #             temp = self.p.new('dob_olivette_w2h', 1.0, freeze=True).x
     #             afont.w2h = (temp,temp)
     if p < (1 - p_chuin):
         afont = self.valuefonts.genByName(
             'Kingthings')  #Kingthings,Olivetti, pala.ttf, palab.ttf
         temp = self.p.new('dob_kingthings_s2h', 1.0, freeze=True).x
         afont.s2h = (temp, temp)
         temp = self.p.new('dob_kingthings_w2h', 1.0, freeze=True).x
         afont.w2h = (temp, temp)
     else:
         afont = self.valuefonts.genByName(
             'pala.ttf')  #Kingthings,Olivetti, pala.ttf, palab.ttf
         temp = self.p.new('dob_pala_s2h', 1.0).x
         afont.s2h = (temp, temp)
         temp = self.p.new('dob_pala_w2h', 1.0).x
         afont.w2h = (temp, temp)
     mask, txt = self.renderer.toMask2(afont, txt=txt)
     #move mask
     adapted_mask = self.putMask(mask, (height, x0, y0, angel))
     return Layer(alpha=adapted_mask, color=self.text_col)
Beispiel #10
0
    def genKeyValuePair(self):

        p_line = np.random.rand()
        p_font = np.random.rand()
        afont = None
        var = 0
        numspot = 0
        if p_font < 0.6:  # typewriter -- travelling
            afont = self.createParametricFont('travel')
            var = np.random.randint(0, 6)
            numspot = np.random.randint(20, 30)
        else:  # chu in -- para or parab
            afont = self.createParametricFont('pala.ttf')

        if p_line < 0.333:  # Name
            keytxt = u' tên:' + u'.' * 100
            valuetxt = self.namegen.gen()
            #             valuetxt = u'TRƯƠNG GIA LỢI'
            self.width = random.randint(550, 648)
        elif p_line < 0.666:  # Nguyenquan 1
            keytxt = u'tuán:' + u'.' * 100
            valuetxt = self.nguyenquan1.gen()
            self.width = random.randint(459, 548)
        else:  # Nguyen quan 2
            keytxt = u'tttt:' + u'.' * 100
            valuetxt = self.nguyenquan2.gen()
            self.width = random.randint(720, 764)

        if np.random.rand() < 0.02:
            valuetxt = u' '
        self.buildCommonParams()
        key_x0 = int(
            self.p.new('key_x0', self.width / 2, paramrange=(0, self.width)).x)
        key_y0 = int(
            self.p.new('key_y0', self.height / 2,
                       paramrange=(0, self.height)).x)
        x0 = int(
            self.p.new('value_x0', self.width / 2,
                       paramrange=(0, self.width)).x)
        y0 = int(
            self.p.new('value_y0',
                       self.height / 2,
                       paramrange=(0, self.height)).x)
        keyfont = self.createParametricFont('arial')
        key_a = self.p.new('key_angle', 0, paramrange=(-5, 5)).x
        value_a = self.p.new('value_angle', 0, paramrange=(-5, 5)).x
        key_height = int(
            self.p.new('key_height', 0.5, paramrange=(0.3, 0.8)).x *
            self.height)
        value_height = int(
            self.p.new('value_height', 0.5, paramrange=(0.3, 0.8)).x *
            self.height)

        mask, txt = self.renderer.toMask2(keyfont, txt=keytxt)
        adapted_mask = self.putMask(mask, (key_height, key_x0, key_y0, key_a))
        lnamekey = Layer(alpha=adapted_mask, color=self.text_col)

        mask, txt = self.renderer.toMask2(afont, txt=valuetxt, var=var)
        adapted_mask = self.putMask(mask, (value_height, x0, y0, value_a))
        if self.overlap:
            return None, None
        lnameval = Layer(alpha=adapted_mask, color=self.text_col)

        above = rstr.rstr('ABC0123456789abcdef ', len(valuetxt))
        below = rstr.rstr('ABC0123456789abcdef ', len(valuetxt))
        mask, txtabove = self.renderer.toMask2(afont, txt=above)
        print mask.shape
        adapted_mask = self.putMask(
            mask, (self.height / 2, random.randint(
                0, self.width), -self.height / 8, value_a))
        labove = Layer(alpha=adapted_mask, color=self.text_col)
        labove.alpha = random.uniform(0.4, 0.95) * labove.alpha
        mask, txtbelow = self.renderer.toMask2(afont, txt=below)
        adapted_mask = self.putMask(
            mask, (self.height / 2, random.randint(
                0, self.width), self.height * 9 / 8, value_a))
        lbelow = Layer(alpha=adapted_mask, color=self.text_col)
        lbelow.alpha = random.uniform(0.4, 0.95) * lbelow.alpha

        lGuiBG = self.buildGuillocheBG()
        l_bg = Layer(alpha=255 * np.ones((self.height, self.width), 'uint8'),
                     color=self.bg_col)
        ### EFFECTS
        lGuiBG.alpha = random.uniform(0.4, 0.7) * lGuiBG.alpha
        lnamekey.alpha = random.uniform(0.4, 0.95) * lnamekey.alpha
        lnameval.alpha = self.si.inkeffect(lnameval.alpha, numspot=numspot)
        lnameval.alpha = self.si.matnet(lnameval.alpha)
        if numspot > 0:
            lnameval.alpha = self.si.sonhoe(lnameval.alpha)
#         lnameval.alpha = self.si.blur(lnameval.alpha)
### MERGES
        layers = [lnameval, lnamekey, labove, lbelow, lGuiBG, l_bg]
        blends = ['normal'] * len(layers)
        nameline = self.colorize.merge_down(layers, blends).color
        nameline = self.si.addnoise(nameline)
        nameline = self.si.heterogeneous(nameline)
        nameline = self.si.distort(nameline)
        #         nameline = self.si.colorBlob(nameline)
        return nameline, no_accent_vietnamese(txt)