看總結直接拉最後
這裏很大程度是因爲圖片大小不一致,可以通過 resize命令來進行圖片的歸一化.
如果是通過captcha庫裏面的ImageCaptcha生成的驗證碼,百度上 沒有任何資料說可以改變圖片大小作爲訓練的.但是直接看他的代碼得知,他是可以設置圖片長寬和大小的
class ImageCaptcha(_Captcha):
"""Create an image CAPTCHA.
Many of the codes are borrowed from wheezy.captcha, with a modification
for memory and developer friendly.
ImageCaptcha has one built-in font, DroidSansMono, which is licensed under
Apache License 2. You should always use your own fonts::
captcha = ImageCaptcha(fonts=['/path/to/A.ttf', '/path/to/B.ttf'])
You can put as many fonts as you like. But be aware of your memory, all of
the fonts are loaded into your memory, so keep them a lot, but not too
many.
:param width: The width of the CAPTCHA image.
:param height: The height of the CAPTCHA image.
:param fonts: Fonts to be used to generate CAPTCHA images.
:param font_sizes: Random choose a font size from this parameters.
"""
def __init__(self, width=200, height=100, fonts=None, font_sizes=None):
self._width = width
self._height = height
self._fonts = fonts or DEFAULT_FONTS
self._font_sizes = font_sizes or (42, 50, 56)
self._truefonts = []
在創建對象的時候給他賦值就可以.
基本出現這個錯誤就是圖片大小不一致,或者傳入的圖片處理過程中出錯的. 把圖片輸出一下看看圖片屬性很好排查的