help me solve so it crops the found text so you see the full width of the original…
- User
help me solve so it crops the found text so you see the full width of the original picture but the height of the found pattern
import cv2 import pytesseract import re
Load image and convert to grayscale
image = cv2.imread("vavavav.png") gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) text = pytesseract.image_to_string(image)
Get verbose data including bounding boxes
data = pytesseract.image_to_data(gray, output_type=pytesseract.Output.DICT)
Define the pattern to search for
pattern = r"Tovchnebaby|Tovchnèbaby|Tovchne\s*baby|Touchmebaby" found = False
Iterate over each text item
for i in range(len(data['text'])): print(data) if re.search(pattern, data['text'][i], re.I): x = data["left"][i] y = data["top"][i] w = data["width"][i] h = data["height"][i]
code# Keep full x-axis length crop = image[y:y+h-20, 0:image.shape[1]] cv2.imshow('crop',crop) input("Press any key to continue...") # Extract number from crop text = pytesseract.image_to_string(crop) print(text) num = re.search(r'\d+', text) if num: print(int(num.group())) else: print("No number found") breakif not found: print("No match found for the pattern.")
- Assistant
- User
it just keeps being a gray screen
- Assistant