utility.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:goldmine 作者: Armored-Dragon 项目源码 文件源码
def ocr(self, ctx):
        """OCR an image.
        Usage: ocr [attach an image]"""
        or_check_perms(ctx, ('bot_owner',))
        warnings.simplefilter('error', Image.DecompressionBombWarning)
        if ctx.message.attachments:
            with async_timeout.timeout(5):
                async with self.bot.cog_http.get(ctx.message.attachments[0].proxy_url) as r:
                    raw_image = await r.read()
        else:
            await ctx.send(':warning: No attachment found.')
            return
        img_bytes = BytesIO(raw_image)
        image = Image.open(img_bytes)
        text = tesserocr.image_to_text(image)
        if text:
            await ctx.send(text)
        else:
            await ctx.send('No results.')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号