I want to detect follow texts from the image but opencv is unable to detect the text. can anyone suggest me another way to find it?
Asked
Active
Viewed 489 times
1 Answers
1
Well, One way can be you build your own convolution neural network(CNN) that detect letters/alphabet from the images
You can generate your own database using these code, this code will generate the image of particular letter
You may need to modify the code , because it might not having folder at a given path and you may require to deal a bit with hard-code value(static)
import os
import matplotlib.font_manager
from PIL import Image, ImageDraw , ImageFont
def rotate_image(image_to_rotate, font_index, parent_folder):
src_im = Image.open(image_to_rotate)
angle = 0
while(angle < 15):
angle += 5
size = 320, 320
dst_im = Image.new("RGBA", (320,320), "black" )
im = src_im.convert('RGBA')
rot = im.rotate( angle, expand=1 ).resize(size)
dst_im.paste( rot, (0, 0), rot )
r_img_dir = "%s\%s%s%s%s" % ( parent_folder, str(fonts.index(font)).zfill(5), "_rotated_by_", str(angle), ".png")
dst_im.save(r_img_dir)
chars = []
for i in range(65,91): # Fix me
chars.append(chr(i))
for k in range(10):
chars.append(k)
for ch in chars: # Remove me [:1]
char= str(ch) # Fix me use instance of to check if int or Str ..
os.makedirs(os.path.join('folder', char)) # Fix me
fonts = matplotlib.font_manager.findSystemFonts(fontpaths=None, fontext='ttf')
p_folder = "%s\%s" % ( 'folder', char )
font_count =0
for font in fonts: # Remove me [:10]
get_str_for_spt = font[0:17]
font_name = font.replace(get_str_for_spt,"")
font_count += 1
if font_count > 10:
break
img = Image.new('RGB', (320, 320), color = (0,0,0)) # make it - 16x16 in place of 32x32
d = ImageDraw.Draw(img)
img_font = ImageFont.truetype(font, 300) # make it 12 in place of 16
d.text((0,0),char, font=img_font)
img_save_dir = "%s\%s_%s%s" % ( p_folder, str(fonts.index(font)).zfill(5),font_name, ".png")
img.save(img_save_dir)
rotate_image(img_save_dir, str(fonts.index(font)).zfill(5), p_folder)
print("Executed")
You can also take reference from following links
https://www.geeksforgeeks.org/text-detection-and-extraction-using-opencv-and-ocr/
Detect text area in an image using python and opencv

Aakash Mehta
- 11
- 2