Skip to content

Instantly share code, notes, and snippets.

import tensorflow as tf
from keras.preprocessing.image import ImageDataGenerator
# creating a sequential model
cnn = tf.keras.models.Sequential()
# adding convolution layer to network
cnn.add(tf.keras.layers.Conv2D(filters=32, kernel_size=3, activation='relu', input_shape=[64, 64, 3]))
# adding pooling layer to network
@akash-ch2812
akash-ch2812 / Crop_and_OCR.py
Last active May 4, 2023 10:27
Crop and image first and then apply OCR
import pytesseract
pytesseract.pytesseract.tesseract_cmd = r'C:\Users\Akash.Chauhan1\AppData\Local\Tesseract-OCR\tesseract.exe'
# load the original image
image = cv2.imread('Original_Image.jpg')
# get co-ordinates to crop the image
c = line_items_coordinates[1]
# cropping image img = image[y0:y1, x0:x1]
@akash-ch2812
akash-ch2812 / Marking_ROI.py
Last active January 17, 2024 06:11
Python code for marking regions of interest in an image for OCR
# use this command to install open cv2
# pip install opencv-python
# use this command to install PIL
# pip install Pillow
import cv2
from PIL import Image
def mark_region(imagE_path):
@akash-ch2812
akash-ch2812 / PDF_to_Image.py
Created July 1, 2020 06:44
Code for converting PDF file to Image in Python
from pdf2image import convert_from_path
pdfs = r"provide path to pdf file"
pages = convert_from_path(pdfs, 350)
i = 1
for page in pages:
image_name = "Page_" + str(i) + ".jpg"
page.save(image_name, "JPEG")
i = i+1