├── TextImage.png ├── TextImage2.png └── main.py /TextImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rafigeovazi/NWord-Classifier/main/TextImage.png -------------------------------------------------------------------------------- /TextImage2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rafigeovazi/NWord-Classifier/main/TextImage2.png -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | import pytesseract 4 | from PIL import ImageGrab 5 | 6 | pytesseract.pytesseract.tesseract_cmd = r'C:/Program Files/Tesseract-OCR/tesseract.exe' 7 | 8 | def detect_and_highlight_N(image): 9 | rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) 10 | boxes = pytesseract.image_to_boxes(rgb) 11 | 12 | h, w, _ = image.shape 13 | 14 | for b in boxes.splitlines(): 15 | b = b.split() 16 | char = b[0] 17 | x, y, x2, y2 = int(b[1]), int(b[2]), int(b[3]), int(b[4]) 18 | 19 | y = h - y 20 | y2 = h - y2 21 | 22 | if char.upper() == "N": 23 | cv2.rectangle(image, (x, y2), (x2, y), (255, 255, 255), -1) 24 | cv2.putText(image, "N", (x - 10, y - 5), cv2.FONT_HERSHEY_COMPLEX, 2.5, (0, 0, 0), 5) 25 | 26 | return image 27 | 28 | while True: 29 | img = np.array(cv2.imread("TextImage.png")) 30 | processed_img = detect_and_highlight_N(img) 31 | 32 | cv2.imshow("Text Detection (Highlight N)", processed_img) 33 | 34 | if cv2.waitKey(1) & 0xFF == ord('q'): 35 | break 36 | 37 | cv2.destroyAllWindows() 38 | --------------------------------------------------------------------------------