import pytesseract
from wand.image import Image
def ocr_core(file_path:str):
with Image(filename=file_path) as img:
img.resize(1200,900)
img_arr = img.make_blob('jpeg')
return pytesseract.image_to_string(img_arr)
```The provided Python code is designed for performing Optical Character Recognition (OCR) on an image using the Tesseract OCR engine integrated with the Wand image manipulation library. Here's a step-by-step explanation of how the code works:
1. **Importing necessary libraries**:
- `import pytesseract`: Imports the pytesseract library, which provides the OCR functionality.
- `from wand.image import Image`: Imports the Image class from the Wand library, which allows for image manipulation and conversion.
2. **Defining the `ocr_core` function**:
- This function takes a single argument, `file_path`, which is the path to the image file on which OCR will be performed.
3. **Image pre-processing using Wand**:
- **Loading the image**: The Wand Image class is used to load the image specified by `file_path`.
- **Resizing the image**: The image is resized to a resolution of 1200x900 pixels. This may help improve OCR accuracy by making the characters larger and more distinct.
- **Converting to JPEG**: The resized image is converted to the JPEG format using the `make_blob` method.
4. **Performing OCR using Tesseract**:
- `img_arr` contains the JPEG-formatted image data, which is passed to the `pytesseract.image_to_string` function.
- `image_to_string` performs OCR on the image data and returns the recognized text as a string.
5. **Returning the OCR result**:
- The function returns the OCR result, which is the extracted text from the image.
Image: www.pinterest.com
Image: www.flickr.com
How Much Does It Cost To Remove A Dew Claw