pytesseract.pytesseract.tesseract_cmd = "C:\Program Files (x86)\Tesseract-OCR\tesseract.exe"
def extract_text(image):
gray = image.convert('L')
enhancer = ImageEnhance.Contrast(gray)
enhanced_image = enhancer.enhance(2)
enhanced_image = enhanced_image.filter(ImageFilter.GaussianBlur(radius=.3))
enhanced_image.save("processed_image.png")
text = pytesseract.image_to_string(enhanced_image, config='--psm 12')
print(f'{text=}')
return text
@interactions.slash_command("predict", description="Predict the location of an uploaded image")
@interactions.slash_option("image", "Upload an image", opt_type=interactions.OptionType.ATTACHMENT, required=True)
async def predict(ctx: interactions.SlashContext, image: interactions.Attachment):
await ctx.defer()
url = image.url
image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
enhancer = ImageEnhance.Contrast(image)
enhanced_image = enhancer.enhance(1.3)
# Convert the enhanced image to a tensor and ensure values are in the range [0, 1]
transform = transforms.Compose([
transforms.ToTensor()
])
image_tensor = transform(enhanced_image).unsqueeze(0).to(device)
extracted_text = extract_text(enhanced_image)
I am not sure why my pytesseract is returning gibberish, I am unsure why getting these outputs.image I am submitting That results in the following output:
text=”m msnnnu MvInIA6=Fmcem’x4Ir;unq Dnvuvauou 53523nn3 mm nyzenq795nx3I)1r>cmePmoe:.xn- 531463 mynn1; I92I)xl2I)0,IMHznn”
I have tried changing the config, changing the filters, removing the filters, etc. I have updated pytesseract via pip, I am not sure what else there is to do. Anything help would be appreciated.