12/22/2023 0 Comments Easy screen ocr fullThis all works fine, but tesseract is not working on cells image which has text of length 2 or less. Result from tesseract: return empty string. I have tried resizing the image(which I knew wouldn't work), also tried appending dummy text to the image but the result was bad(was working only for few and I didn't the exact location to append the dummy text in the image) It also returns empty for numbers of text length 2 or less. It would be great if someone could help me with this. So I finally came with a workaround for this situation. ![]() The situation being tesseract-OCR giving empty string when the image contains only 1 or 2 length string(eg "1" or "25"). To get output in this situation I appended the same image multiple time at the original image so as to make its length greater than 2. For example, if the original image contained only "3", I appended "3" image(the same image) 4 more times and thereby making it an image which contains the text "33333". Please see code for reference, hope this helps: import pytesseract # pip3 install pytesseract We then give this image to tesseract which gives output "33333"(most of the times).Then we just have to replace space with blank in the text output from the Tesseract and divide the resulting string length by 5 to get the index up to which we would want to text out from the whole text. #Easy screen ocr not working with 4k install# A wait after starting ORC engine and focusing window, to help it all be in the correct state before moving the mouse by OCR start is as well recommended, the 5 sec is excessive but as it works you could test 4 3 2 etc. Method which calls tesseract for OCR or calls our workaround code if we get an empty string from tesseract output. #Easy screen ocr not working with 4k code# Mask = np.zeros(gray.shape,np.uint8) # mask image the final image without small pieces Method to crop the dilated part of the image def cropOutMyImg(gray, OrigImg): Return cv2.dilate(img,kernel,iterations = iterations) Ret,img = cv2.threshold(img, 0, 1, cv2.THRESH_BINARY_INV) Method for dilation.This method is used to dilate only the text region of the image def generate_blocks_dilation(img, yDir, xDir, iterations): TextA = pytesseract.image_to_string(concateImg) Img = cv2.dilate(img,kernelV,iterations = 1)ĬoncateImg = np.concatenate((image, image), axis = 1)ĬoncateImg = np.concatenate((concateImg, image), axis = 1) Img = cv2.dilate(img,kernelH,iterations = 1) # we dilation to get only the text portion of the image and not the whole image Img = generate_blocks_dilation(croppedImage, yDir, xDir, iterations) If text.strip() = '': # program that handles our problem Text = pytesseract.image_to_string(croppedImage) To know the ORC can read the text, you can add an extract text with ORC and check that the text you look for is in the. ![]() #Easy screen ocr not working with 4k code#.#Easy screen ocr not working with 4k install#.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |