You are on page 1of 3

Assighnment#1 -CV

Name: M. Hanzalah Hashmi

Reg #: FA20-BCS-015

Section: A

PYTHON CODE:
!pip install easyocr

# Import necessary libraries


import cv2
from google.colab.patches import cv2_imshow
import easyocr
# Load the input image
img = cv2.imread('/content/636318268614760881-IAT-Kettles7.jpg')
cv2_imshow(img)

# Convert the image to grayscale


gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2_imshow(gray)

# Perform MSER detection on the grayscale image


mser = cv2.MSER_create()
regions,_= mser.detectRegions(gray)
for region in regions:
x, y, w, h = cv2.boundingRect(region)
cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)

cv2_imshow(img)

#Perform OCR after MSER detection on image


reader=easyocr.Reader(['en','en'])
results=reader.readtext(gray)
for x in results:
print(x[1])

Output:
Bury
A576
Manchester A6
(A56)

You might also like