Skip to main content

OCR - Get extracted text via url or endpoint?

Comments

1 comment

  • Raz Ziv

    Hi Dara,

    Yes, it is possible to retrieve the OCR text via an API call.

    In case you've already run the OCR analysis on the specific image, you can use the resource API to list all details related to that resource. One of the properties that will be returned in the JSON response is 'info' and underneath it, you will see the following hierarchy: 'ocr'->'adv_ocr'->'data', which will list all the different texts extracted from the image.

    So for example (in PHP), you will be able to retrieve the text using the following code:

    $api = new \Cloudinary\Api();
    
    $result = $api->resource('<public_id>');
    
    $ocr_info = $result['info']['ocr']['adv_ocr']['data'];

    In case you've never run an OCR analysis on that image and you want to do it for the first time via the API, you can do so using our update API. An example request (in PHP again):

    $result = \Cloudinary\Api::update("<public_id>", 
        array("ocr" => "adv_ocr")
    );

    The result will have the OCR text returned in a similar way as in the resource API response.

    Lastly, you can also request an OCR detection when uploading a new image, as part of the upload request:

    $result = \Cloudinary\Uploader::upload("<file_path>", 
        array("ocr" => "adv_ocr")
    );

    The upload response will also consist of the OCR property which you can store on your end, or alternatively, create additional resource details requests in the future, to get that information on demand whenever needed.

    Best,
    Raz

    0

Post is closed for comments.