[英]Finding white rectangular areas in given image to increase OCR results
Basically, I am trying to detect labels on boxes and these labels are white.基本上,我试图检测盒子上的标签,而这些标签是白色的。 Every label has own serial number and letter.
每个label都有自己的序列号和字母。 I am using EasyOCR for detecting numbers and letters but sometimes EasyOCR can not detect texts accurate but If I take images from closer range, It detects very well.
我正在使用 EasyOCR 检测数字和字母,但有时 EasyOCR 无法准确检测文本,但如果我从更近的范围拍摄图像,它检测得很好。 So, I need to crop label area with using image processing method.
因此,我需要使用图像处理方法裁剪 label 区域。 After that I will give it to EasyOCR to better results.
之后我会把它交给 EasyOCR 以获得更好的结果。 I am open to any idea!
我愿意接受任何想法!
My Example Image:我的示例图片:
I had solved the issue by cropping image based on image dimension with respect to the rack columns and rack rows.我通过根据机架列和机架行的图像尺寸裁剪图像解决了这个问题。 The code is,
代码是,
import easyocr
import cv2
image = cv2.imread('2.jpg')
h, w, _ = image.shape
rack_rows = 3
rack_cols = 3
total_boxes = []
reader = easyocr.Reader(['en'])
for row in range(rack_rows):
for col in range(rack_cols):
# crop individual boxes based on dimension of image
cropped_image = image[row*(int(h/3)) : ((row+1) * int(h/3)),(col*(int(w/3))) : ((col+1)* int(w/3)),:]
# resize image based on custom size
resize_image = cv2.resize(cropped_image,(800,800))
# write cropped image to feed easyocr
cv2.imwrite(f'image{row}_{col}.png',resize_image)
# easyocr execution
result = reader.readtext(f'image{row}_{col}.png')
texts = [detection[1] for detection in result if detection[2] > 0.4]
if len(texts[1])!=4:
texts.pop(1)
total_boxes.append(texts)
print(total_boxes)
Here I resized the image based on custom dimension (800,800) to feed easyocr after dimensional cropping.在这里,我根据自定义尺寸 (800,800) 调整了图像的大小,以便在尺寸裁剪后提供 easyocr。 I haven't use any image preprocessing technique rather than resizer here.
我没有使用任何图像预处理技术,而不是这里的调整器。 The output what I gained is,
我得到的output是,
[['S', '5607'], ['N', '4457'], ['U', '4017'], ['P', '4529'], ['X', '3311'], ['J', '2075'], ['W', '8075'], ['M', '9623'], ['K', '5412']]
Happy coding:)快乐的编码:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.