diff --git a/Class 2 Homework.ipynb b/Class 2 Homework.ipynb index 02b6ea3..a5d8762 100644 --- a/Class 2 Homework.ipynb +++ b/Class 2 Homework.ipynb @@ -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)" ] @@ -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 } diff --git a/image.png b/image.png new file mode 100644 index 0000000..3e0820a Binary files /dev/null and b/image.png differ diff --git a/processed_image.png b/processed_image.png new file mode 100644 index 0000000..044b405 Binary files /dev/null and b/processed_image.png differ