doc-exports/docs/ocr/umn/ocr_01_0032.html
Sheng, Lichang 86871abfe4 OCR usermanual 20240111 v2
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com>
Co-authored-by: Sheng, Lichang <lichangsheng1@noreply.gitea.eco.tsi-dev.otc-service.com>
Co-committed-by: Sheng, Lichang <lichangsheng1@noreply.gitea.eco.tsi-dev.otc-service.com>
2024-01-17 10:42:31 +00:00

17 lines
935 B
HTML

<a name="ocr_01_0032"></a><a name="ocr_01_0032"></a>
<h1 class="topictitle1">How Can I Get the Base64 Encoding of an Image?</h1>
<div id="body0000001752942369"><p id="ocr_01_0032__p975312616332">To recognize an image, it must first be converted to its Base64 coding. This section provides an example using Python to explain how to convert a local image to Base64 code. You can also use an online conversion tool.</p>
<p id="ocr_01_0032__p1275311613316">Replace <strong id="ocr_01_0032__b126396295793854">d:\demo.jpg</strong> in the code with the actual image path.</p>
<pre class="screen" id="ocr_01_0032__screen147531468336">import base64
with open("d:\demo.jpg", "rb") as image_file:
encoded_string = base64.b64encode(image_file.read()).decode()
print(encoded_string)</pre>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="ocr_01_0046.html">APIs</a></div>
</div>
</div>