Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 45 additions & 8 deletions Class 2 Homework.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,47 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Drive-Thru\n",
"Testing\n",
"\n",
"APPOINTMENT []\n",
"ONLY 1\n",
"\n",
"=>\n",
"\n",
"\n"
]
}
],
"source": [
"from PIL import Image\n",
"import pytesseract #pip install pytesseract first\n",
"from PIL import Image, ImageEnhance, ImageFilter\n",
"import pytesseract\n",
"\n",
"pytesseract.pytesseract.tesseract_cmd = r'C:\\Program Files\\Tesseract-OCR\\tesseract.exe'\n",
"\n",
"# Load an image using Pillow (PIL)\n",
"image = Image.open('image.png')\n",
"\n",
"# Preprocess\n",
"image = image.convert('L')\n",
"\n",
"contrast_enhancer = ImageEnhance.Contrast(image)\n",
"image = contrast_enhancer.enhance(5.0)\n",
"\n",
"image = image.filter(ImageFilter.MedianFilter())\n",
"\n",
"image.save('processed_image.png')\n",
"\n",
"# Perform OCR on the image\n",
"text = pytesseract.image_to_string(image)\n",
"config = '--oem 3 --psm 3 -l eng'\n",
"text = pytesseract.image_to_string(image, config=config)\n",
"\n",
"print(text)"
]
Expand Down Expand Up @@ -169,15 +198,23 @@
],
"metadata": {
"kernelspec": {
"display_name": "base",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"version": "3.8.19"
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.9"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
Binary file added image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added processed_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.