Python python 实现图形验证码识别问题

黑山老妖 · 2019年06月21日 · 最后由 a2021 回复于 2019年06月21日 · 2060 次阅读

已知,python 的库 pytesseract 和 image 可以去识别图形验证码
但是只能是图片存储在某个路径下,然后去 open,识别
如果有个图片,是这种格式
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKAAAABGCAMAAAB8DG+AAAAAP1BMVEUAAAA9fEB6uX1SkVVvrnIPThJPjlJ5uHwubTEcWx9TklZioWU1dDh3tno9fEA0czd3tnowbzMUUxcKSQ0xcDSd5F48AAAAAXRSTlMAQObYZgAAA0xJREFUeJzsmduO4yAMhm2qNu1Fm4u+/7uu0nDwESZAtb2IpdWMMsR8/NjGZOG000477bTTTjuty3D7h58f8x3PcIMbHe4/hNPX69XnNGx4OIUQpXG+HkKEEIJw1Y0HWbo5gNFRwDkKRjjqegSQLBemCChSQwEei0GxFzNyRABpwGPOmIIzTPHYhI/H44C7mdXKBjT4KGHwvU0upQaNuTk7YHocQnAGz6p7VY+uguV5yHB8SyfVvQaMt8dCWLOyf0FBvcUmNCCu9DmagHYFWOYDWqPWdUW+Cl7xXMJlGSGUHp0yyBVEIJVOBGH8lWbPOJ+c1xgEZUJxXCOoGDQOzG5Aq1NQe76h0X3ktYXy5a4NeKPwHGFMpzraC0dTQTABkycSo/f7HeD53AjD5XLpI0zrtgDTrpe/1PiYgpvd7zth5OsizAraSZge5fCPD1Jyoqo+NHsi4Md6AYEUWP9gyeyF70PI+ViSbc5mAXIY9iRBC9AIiCVGUa0ux2AhHOcTrQ1XDksO74D5DXqooFjfLEO79QJS44CQLsuSiRD52Sw8TOJDa5OA1TikA0kxAcDK4bz/vqfUbYSw0XlFBQWHzGFxjBS+T0rdbr2EWE0QUAqqvcx++H2pbMpxBVl0mROiraB5fZbvQVnOASY1OwILbz1Ej0+vNW7l+WzqbmFZXZDlwQDkParsaar+RwERXTWMVjGv5a+I/RKSS48zExdWaILYvJ7jKGMJJMcBkvJIoo/9saWhWSGOQVYnUPcjeTNp8Dlt5iRDYCkhZzJTP7+pSuc3EX0JxXC0P259jRCNdAcfkI9Dq9nm/td1FRMeXAWNIS2hUTw9CWlOMz5B2BT6/X5bfEBzsuoO/QIUAa/Xax2wVrve70JYtos0gqJftF25/iPf9Rr9OIAVFTNgbuL9OO+qvwgRcF+bisFWPiVAzE2p+2ZvWibAyuts4zQh/VKv38udzAihl9R5JqfIZhBHZ78iHjYrzS0GI6Brs3MFx25sfo8iQfRNzpenUz+VCdRdHVF8XWtO3yWfkavEYcVIpROxNfnY9Pn+YFnHZuD+L1MNwW8attPqtN+y8h9qv2khTCYc/PaorBvQSZLhr6PSegHdNJ6toB2D/wIAAP//DV8OoEXRcU8AAAAASUVORK5CYII=

咋去识别呢

共收到 1 条回复 时间 点赞

这是 base64 编码的图片数据,用 base64 去解码后就可以了

import base64
img_base64 = 'iVBORw0KGgoAAAANSUhEUgAAAKAAAABGCAMAAAB8DG+AAAAAP1BMVEUAAAA9fEB6uX1SkVVvrnIPThJPjlJ5uHwubTEcWx9TklZioWU1dDh3tno9fEA0czd3tnowbzMUUxcKSQ0xcDSd5F48AAAAAXRSTlMAQObYZgAAA0xJREFUeJzsmduO4yAMhm2qNu1Fm4u+/7uu0nDwESZAtb2IpdWMMsR8/NjGZOG000477bTTTjuty3D7h58f8x3PcIMbHe4/hNPX69XnNGx4OIUQpXG+HkKEEIJw1Y0HWbo5gNFRwDkKRjjqegSQLBemCChSQwEei0GxFzNyRABpwGPOmIIzTPHYhI/H44C7mdXKBjT4KGHwvU0upQaNuTk7YHocQnAGz6p7VY+uguV5yHB8SyfVvQaMt8dCWLOyf0FBvcUmNCCu9DmagHYFWOYDWqPWdUW+Cl7xXMJlGSGUHp0yyBVEIJVOBGH8lWbPOJ+c1xgEZUJxXCOoGDQOzG5Aq1NQe76h0X3ktYXy5a4NeKPwHGFMpzraC0dTQTABkycSo/f7HeD53AjD5XLpI0zrtgDTrpe/1PiYgpvd7zth5OsizAraSZge5fCPD1Jyoqo+NHsi4Md6AYEUWP9gyeyF70PI+ViSbc5mAXIY9iRBC9AIiCVGUa0ux2AhHOcTrQ1XDksO74D5DXqooFjfLEO79QJS44CQLsuSiRD52Sw8TOJDa5OA1TikA0kxAcDK4bz/vqfUbYSw0XlFBQWHzGFxjBS+T0rdbr2EWE0QUAqqvcx++H2pbMpxBVl0mROiraB5fZbvQVnOASY1OwILbz1Ej0+vNW7l+WzqbmFZXZDlwQDkParsaar+RwERXTWMVjGv5a+I/RKSS48zExdWaILYvJ7jKGMJJMcBkvJIoo/9saWhWSGOQVYnUPcjeTNp8Dlt5iRDYCkhZzJTP7+pSuc3EX0JxXC0P259jRCNdAcfkI9Dq9nm/td1FRMeXAWNIS2hUTw9CWlOMz5B2BT6/X5bfEBzsuoO/QIUAa/Xax2wVrve70JYtos0gqJftF25/iPf9Rr9OIAVFTNgbuL9OO+qvwgRcF+bisFWPiVAzE2p+2ZvWibAyuts4zQh/VKv38udzAihl9R5JqfIZhBHZ78iHjYrzS0GI6Brs3MFx25sfo8iQfRNzpenUz+VCdRdHVF8XWtO3yWfkavEYcVIpROxNfnY9Pn+YFnHZuD+L1MNwW8attPqtN+y8h9qv2khTCYc/PaorBvQSZLhr6PSegHdNJ6toB2D/wIAAP//DV8OoEXRcU8AAAAASUVORK5CYII='
img_bin = base64.decodestring(img_base64)
with open('base64.png', 'wb') as f:
    f.write(img_bin)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册