Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

DIGIT RECOGNITION BASED ON USING TEMPLATE

MATCHING

SUBMITTED BY:
Alma Ferdaus Sabiha
ID: 1803510201734
Department: CSE
Section: B
➢ Objective

■ Recognizing digit from given digit image using template matching.

Figure 01: Process example of digit recognition


➢ Motivation

1. Simplicity:
Template Matching is conceptually simple and easy
…… to understand.
2. Efficiency:
It can be computationally efficient for simple object
… recognition tasks.
3. Localization:
Template Matching provides precise localization of
…. objects.
➢ Application

Uses (Number Recognitions) :

1. Object Detection:
Locate specific objects within images or video frames.
Example: Finding a logo on a product package.
2. Character Recognition:
Identify characters in scanned documents.
Example: Reading handwritten digits on checks.
3. Medical Imaging:
Detecting anomalies in medical images.
Example: Identifying tumors in MRI scans.
➢ Framework
Start

Digit Acquisition

Pre-Processing

Template Matching

Sorting

Text Creation

Image Conversion

End

Figure 02: Flowchart of digit recognition based on using template matching.


➢ Processing Example

Input:
2
Gray Scale Image:

Binary Scale Image:

Output:
Input:
7
Gray Scale Image:

Binary Scale Image:

Output:
➢ Conclusion

1. Template matching is a straightforward technique for digital recognition.


2. Effective for basic pattern detection and simple object identification.
3. However, limitations in handling complex patterns and real-world variability
…… must be considered.

NCC(merits):
Robust to variations in lighting and contrast.
Can handle simple transformations like rotation and scaling.

NCC(demerits):
NCC is sensitive to noise in the images.
Noisy images can lead to incorrect matches due to noisy correlations.
➢ Appendix
!pip install opencv.python
!pip install scikit-image
!pip install numpy
import cv2
import numpy as np
import matplotlib.pyplot as plt
from google.colab.patches import cv2_imshow
# Read the main image
img_rgb = cv2.imread('/content/6.jpeg')
# Convert it to grayscale
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
cv2_imshow(img_gray)
template_rgb = cv2.imread('/content/Template.jpeg')
# Convert it to grayscale
template_gray = cv2.cvtColor(template_rgb, cv2.COLOR_BGR2GRAY)
cv2_imshow(template_gray)
template= cv2.imread('/content/Template.jpeg', 2)
ret, bw_template = cv2.threshold(template, 170,255,cv2.THRESH_BINARY)
# converting to its binary form
template= cv2.threshold(template,170, 255,cv2.THRESH_BINARY)
cv2_imshow(bw_template)
cv2.waitKey(0)
cv2.destroyAllWindows()
import cv2
from google.colab.patches import cv2_imshow
def template_matching(image_path,template_path):
# Load the template and the image
image= cv2.imread('/content/6.jpeg', 0)
template= cv2.imread('/content/Template.jpeg', 0)
# Get the width and height of the template
w, h = image.shape[::-1]
# Perform template matching
result = cv2.matchTemplate(image, template, cv2.TM_CCOEFF_NORMED)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)

# Get the top-left and bottom-right coordinates of the matched region


top_left = max_loc
bottom_right = (top_left[0] + w, top_left[1] + h)

# Draw a rectangle around the matched region on the original image


matched_image = cv2.imread('/content/Template.jpeg')
cv2.rectangle(matched_image, top_left, bottom_right, (0, 255,0),3)

# Display the result


cv2_imshow(matched_image)
cv2.waitKey(0)
cv2.destroyAllWindows()

# Replace 'template.png' and 'image.png' with the paths of your template


and image files
image_path = '/content/6.jpeg'
template_path = '/content/Template.jpeg'
template_matching( 'image_path','template_path')

You might also like