I want to isolate every character in the following image:
and it should create a rectangular bounding box around each character. My code is creating a circular bounding box. I need to supply these isolated character images to my trained model to predict the character. I haven't done image processing before which leads me to asking such a question.
This is the code I'm using:
# Standard imports
import cv2
import numpy as np;
from PIL import Image
params = cv2.SimpleBlobDetector_Params()
# Change thresholds
params.minThreshold = 10;
params.maxThreshold = 200;
#Filter by Color
params.filterByColor=False
params.blobColor=255
# Filter by Area.
params.filterByArea = False
params.minArea = 50
# Filter by Circularity
params.filterByCircularity = False
params.minCircularity = 0.0785
#
# # Filter by Convexity
params.filterByConvexity = False
params.minConvexity = 0.87
#
# # Filter by Inertia
params.filterByInertia = False
params.minInertiaRatio = 0.01
# Read image
im = cv2.imread("C:\\xx\\testimages\\bw_plate.jpg", cv2.IMREAD_GRAYSCALE)
cv2.threshold(im,200,255,cv2.THRESH_BINARY_INV,im)
# Set up the detector with default parameters.
detector = cv2.SimpleBlobDetector_create(params)
# Detect blobs.
keypoints = detector.detect(im)
# Draw detected blobs as red circles.
# cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS ensures the size of the circle corresponds to the size of blob
im_with_keypoints = cv2.drawKeypoints(im, keypoints, np.array([]), (0, 0, 255),
cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
# Show keypoints
cv2.imshow("Keypoints", im_with_keypoints)
cv2.waitKey(0)
My output with the following code is:
Why is it not detecting 0 and 2 properly? Also how can I create separate jpeg files for every isolated character?
The C++ implementation of my project uses CblobResult class which did the segmentation. Is there any equivalent library in python?
This is what the final output must look like for every character after segmentation: