简体   繁体   中英

ocr image cleansing with python opencv

I'm currently learning about computer vision OCR. I have an image that needs to be scan. I face a problem during the image cleansing.

I use opencv2 in python to do the things. This is the original image:

image = cv2.imread(image_path)
cv2.imshow("imageWindow", image)

I want to cleans the above image, the number at the middle (64) is the area I wanted to scan. However, the number got cleaned as well.

image[np.where((image > [0,0,105]).all(axis=2))] = [255,255,255]
cv2.imshow("imageWindow", image)

What should I do to correct the cleansing here? I wanted to make the screen where the number 64 located is cleansed coz I will perform OCR scan afterwards.

Please help, thank you in advance.

What you're trying to do is called "thresholding". Looks like your technique is recoloring pixels that fall below a certain threshold, but the LCD digit darkness varies enough in that image to throw it off.

I'd spend some time reading about thresholding, here's a good starting place: Thresholding in OpenCV with Python . You're probably going to need an adaptive technique (like Adaptive Gaussian Thresholding), but you may find other ways that work for your images.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM