<jupyter_start><jupyter_text>IMPORT PACKAGES<jupyter_code>import cv2
from matplotlib import pyplot as plt
import numpy as np
import imutils
import easyocr
img =cv2.imread('./image6.jpeg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
plt.imshow(cv2.cvtColor(gray, cv2.COLOR_BGR2RGB))<jupyter_output><empty_output><jupyter_text>APPLY FILTERING and FIND EDGE FOR LOCALIZATON<jupyter_code>bfilter = cv2.bilateralFilter(gray,40,40,40) # Noise Reduction
edged = cv2.Canny(bfilter,40,200) # Edge Detection
plt.imshow(cv2.cvtColor(edged, cv2.COLOR_BGR2RGB))<jupyter_output><empty_output><jupyter_text>FIND CONTOURS AND APPLY MASK<jupyter_code>keypoints = cv2.findContours(edged.copy(),cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
contours = imutils.grab_contours(keypoints)
contours = sorted(contours, key = cv2.contourArea, reverse=True)[0:30]
location = None
for contour in contours:
    approx = cv2.approxPolyDP(contour, 10, True)
    if len(approx) == 4:
        location = approx
        break
location
mask = np.zeros(gray.shape, np.uint8)
new_image = cv2.drawContours(mask, [location], 0,255,-1)
new_image = cv2.bitwise_and(img,img,mask=mask)
plt.imshow(cv2.cvtColor(new_image, cv2.COLOR_BGR2RGB))
(x,y) = np.where(mask==255)
(x1,y1) = (np.min(x), np.min(y))
(x2,y2) = (np.max(x), np.max(y))
cropped_image= gray[x1:x2+1,y1:y2+1]
plt.imshow(cv2.cvtColor(cropped_image, cv2.COLOR_BGR2RGB))<jupyter_output><empty_output><jupyter_text>USE EASY OCR to READ TEXT<jupyter_code>reader = easyocr.Reader(['en'])
results = reader.readtext(cropped_image)
results
crop_image = cropped_image[6:82,30:410]
plt.imshow(cv2.cvtColor(crop_image, cv2.COLOR_BGR2RGB))
text = results[0][1].upper()
text<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13975337639459776, 'fraction_numerical': 0.04462712859659425, 'mean_word_length': 7.649746192893401, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '551884', 'license': 'MIT', 'n_tokens_mistral': 760, 'n_tokens_neox': 728, 'n_words': 106, 'path': 'task_08/NPR.ipynb', 'repo_name': 'suyash0102/summer_internship_program_2021', 'size': '1703'}