def get_text_and_image(self, backgroundColor=None, fontColor=None, fontSizes=(28, )): """ 生成字符序列和对应的图片数据 图片颜色通道是(R,G,B)-> text,image""" charBoxWidth = 15 charBoxHeight = 30 blackBkgColor = ImageCaptcha.random_bkg_color(0, 90) fontColor = ImageCaptcha.random_font_color(180, 250) grayBkgColor = ImageCaptcha.random_bkg_color(130, 220) image = ImageCaptcha(width=charBoxWidth, height=charBoxHeight, backgroundColor=blackBkgColor, fontColor=fontColor, font_sizes=fontSizes) captcha_text = self._random_text() captcha_text = ''.join(captcha_text) filename = GenImageGasMeterStyle1m2.getRandomFilename() # print(filename) captcha_image = Image.open(filename) captcha_image = ImageTool.imageResizePIL(captcha_image, self._picBoxWidth, self._picBoxHeight) dxs = [7, 32, 58, 83, 107] dy = 17 i = 0 def randDy(): return 4 - random.randint(1, 8) for c in captcha_text: desX = dxs[i] charImage = image.generate(c) charImage = Image.open(charImage) captcha_image.paste(charImage, (desX, dy + randDy())) i += 1 if self._imageDepth == 1: # 将彩色图片转换成灰度图图片 captcha_image = ImageTool.convertImgRGB2Gray(captcha_image) captcha_image = np.array(captcha_image) return captcha_text, captcha_image
def get_text_and_image(self,backgroundColor = None, fontColor = None, fontSizes = None): """ 生成字符序列和对应的图片数据 图片颜色通道是(R,G,B)-> text,image""" image = ImageCaptcha(width=self._picBoxWidth, height=self._picBoxHeight, backgroundColor=backgroundColor, fontColor=fontColor, font_sizes=fontSizes) captcha_text = self._random_text() captcha_text = ''.join(captcha_text) captcha = image.generate(captcha_text) captcha_image = Image.open(captcha) if self._imageDepth == 1: # 将彩色图片转换成灰度图图片 captcha_image = ImageTool.convertImgRGB2Gray(captcha_image) captcha_image = np.array(captcha_image) return captcha_text, captcha_image
def get_text_and_image(self, backgroundColor=None, fontColor=None, fontSizes=(28, )): filename = GenImageGasMeterStyle1m2.getRandomFilename() # print(filename) captcha_image = Image.open(filename) captcha_image = ImageTool.imageResizePIL(captcha_image, self._picBoxWidth, self._picBoxHeight) t = FileNameUtil.getFilenameFromFullFilepathname(filename) captcha_text = t[:5] if self._imageDepth == 1: # 将彩色图片转换成灰度图图片 captcha_image = ImageTool.convertImgRGB2Gray(captcha_image) captcha_image = np.array(captcha_image) return captcha_text, captcha_image
def get_text_and_image(self, backgroundColor=None, fontColor=None, fontSizes=None): """ 生成字符序列和对应的图片数据 图片颜色通道是(R,G,B)-> text,image""" charBoxWidth = 20 charBoxHeight = 50 blackBkgColor = ImageCaptcha.random_bkg_color(0, 65) fontColor = ImageCaptcha.random_font_color(180, 250) grayBkgColor = ImageCaptcha.random_bkg_color(130, 220) image = ImageCaptcha(width=charBoxWidth, height=charBoxHeight, backgroundColor=blackBkgColor, fontColor=fontColor) captcha_text = self._random_text() captcha_text = ''.join(captcha_text) captcha_image = Image.new('RGB', (self._picBoxWidth, self._picBoxHeight), grayBkgColor) dx = 4 dy = 7 desX = dx for c in captcha_text: charImage = image.generate(c) charImage = Image.open(charImage) captcha_image.paste(charImage, (desX, dy)) desX += dx + charBoxWidth if self._imageDepth == 1: # 将彩色图片转换成灰度图图片 captcha_image = ImageTool.convertImgRGB2Gray(captcha_image) captcha_image = np.array(captcha_image) return captcha_text, captcha_image