Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Getting the best threshold for each channel

Hi, I'm trying to threshold an image for each channel, but I don't know the best method for determining the best threshold for an image, do you know any algorithms ?

import tesserocr
from PIL import Image
import pytesseract
import matplotlib.pyplot as plt
import cv2
import imutils
import numpy as np

image = cv2.imread(r'c:\ahmed\test2.png')

bin = np.all(np.array(image<131, dtype=np.uint8), axis=2)
inverted = cv2.bitwise_not( np.uint8(255*bin))

cv2.imshow("bin", inverted)


text = pytesseract.image_to_string(inverted, lang='ara')
print(text)
with open(r"c:\ahmed\file.txt", "w", encoding="utf-8") as myfile:
    myfile.write(text)
cv2.waitKey(0)