weixin_39752087
weixin_39752087
2020-12-09 01:24

Creating an ImageToTextTask with from a string containing base64 data

Hi, given a string encoding a png image in base64 (example given below), what is the most straightforward way to create the corresponding ImageToTextTask?

For a quick check, there exists many website which render base64 data, for instance: https://codebeautify.org/base64-to-image-converter# just copy-paste everything in between the "quotes" ;-)

"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFsAAAAYCAYAAACV+oFbAAANZklEQVR42uVZe2xV9R3/vc65t71tobSFUilgwxsBAQVEFJHoMqcJUbapS3BZFt3mHpmLf8zg3JLN+Vg02bIsvrKZmGVziw9chhsqDMZDBspTEaS0hZbSQt+Pe885v99vn+/v3IuXWkqrkmUbyem53HvO+X2+39/n830d3lTx4Fqumce19riJfGmYx3TkSW19ZiKPW6s0lwFTIrRCBFbIkAn6LEMreWClwhnfcx5apUKDsxEqsJ7AmQdcilDjd85kaPA7VyyM8DzOWMiFF4TS4K/1LGOetdqXUeixyPiCcU/ojCeM9W1ocKZD+9waj0e43hqfAycHTsIuDeE3wG7d9/G1hF2EMXbYEON2NmjJQy6BE2fLYYuSAWGHjVhNBQZnDvuMlXRdqJUNuScDuCpk3ARRIhEy/FOZjMes8CULPRsSfu5ZWp8BNzA53GHkEzYFp0qujeRMS2YYDsCwVhpjpLBGWia0EEJrnJnAtgimNc50lzsYDs415/HZclyn4rPAdVpI+BqucM+xWhtPS1/qENdKqyycK7VgMBvmsEgKw6XFooSHwwsGmAQ3DhPD9wZnhUPoSJ5FQdgZYcdnq92ZncXOtCHsDNtAuAmTJDvIpixmmcMvtFU48BCBz7gZ8IEZLACBNGBoAVeGwtMqghsZyCC4ZEEk8SypgN1gfSGM8ylh4FGMnQ5lAJIzK+VZoDCOnI4LaecMOQ+A6bBMurMgkASexUANIwMEAMdgDR5EgMEgZ4ABAqMswHrwtdVYQyt4KJSB9AHShHCygO9BeahLMg49EAHsR0DdZwZMWNEw6zBzhx36MYQ/xuywM7qWGCCcU+HgiLAw53RhBGEnMpwlC1bDTc7Z7qD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zggxzDQxkGIlAyog5FlPv7santCjNe02WyQPmvRQXCbDJtt8mm8Unp1OQBxcXY6Rgsop0VdSAkYJToIgc9sFGCh/hjzMEVU9DjRQoZg85792hDlcETBfUiVMz7xfPTqfmxNdeB+5AtlZd8+WM1+/2V+/8f34Dcz5FDhwpqAu9gVnEZjY+Hk54si3Ry5tYe6KXZViL7Ez2spC3m87iOYlpx4Yql/4f3sCIQRqYwUYKajhvYCrV6PQ4Wx7OlJOzL0u9AE5BglFh5Mkhy6X/tjcwF1ORIr9cEixmt8hl8wFvYBxTsg0MMSrXwFC808QMQ4kFiQGHyMY793YSDOGOnXGsE/nxLm/ea1hcaZisDPPfwIi8Bsac08DwLOYsdtrC7DvRgQ2Mw54bKVBPQIqkcOKwZ/OMwx5lY3U2vziixHjFOYnROOfGuHPYkU9ysTqrSJFVpPokb2AGNjAXs1z6X3on+m+3uSLIg8eQzAAAAABJRU5ErkJggg=="

该提问来源于开源项目:ad-m/python-anticaptcha

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

5条回答

  • weixin_39944944 weixin_39944944 5月前

    See https://github.com/ad-m/python-anticaptcha/blob/master/examples/text.py for Example. You don't have encode anything by hand.

    点赞 评论 复制链接分享
  • weixin_39752087 weixin_39752087 5月前

    There is no encoding by hand: I get that string from the source of a webpage. Contrary to the example I do not have a file to load from the disk (unless I write the data to the disk, but that is silly).

    点赞 评论 复制链接分享
  • weixin_39752087 weixin_39752087 5月前

    I had a look into the source. I think that the easiest way is to add class StringToTextTask which does not redo the encoding into the serialize function. Would you accept a pull request?

    点赞 评论 复制链接分享
  • weixin_39944944 weixin_39944944 5月前

    I can accept PR, which will not force coding on the library side.

    You can for Python 3 use also something like:

    python
    from io import BytesIO
    import base64
    fp = BytesIO(base64.b64decode(url.split(';')[1]))
    
    点赞 评论 复制链接分享
  • weixin_39752087 weixin_39752087 5月前

    Fair enough, BytesIO(base64.b64decode(...)) did the trick without extra effort. Thank you!

    点赞 评论 复制链接分享

相关推荐