Я работаю над проектом, в котором мне удалось успешно обнаружить ячейки табличного изображения, и в каждой ячейке я также пытаюсь обнаружить написанные числа и текст, но мне неоднократно удавалось это сделать, перепробовав так много вариантов. >
Здесь я прикрепил свою последнюю попытку использования pytesseract, хотя я знаю, что pytesseract не подходит для обнаружения рукописного текста. Но тем не менее он определяет 5 из 51, 79 из 71.
!apt-get install -y tesseract-ocr
from google.colab.patches import cv2_imshow
import cv2
import pytesseract
def recognize_digit(image):
# Preprocess the image for OCR
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
clahe = cv2.createCLAHE(clipLimit=0.9, tileGridSize=(8, 8))
equalized = clahe.apply(gray)
threshold = cv2.threshold(equalized, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
denoised = cv2.fastNlMeansDenoising(threshold, h=0)
# Remove horizontal lines
horizontal_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (24,1))
detect_horizontal = cv2.morphologyEx(threshold, cv2.MORPH_OPEN, horizontal_kernel, iterations=2)
cnts = cv2.findContours(detect_horizontal, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
for c in cnts:
cv2.drawContours(image, [c], -1, (255,255,255), 5)
cv2.drawContours(denoised, [c], -1, (0, 0, 0), 5)
cv2.drawContours(threshold, [c], -1, (0, 0, 0), 5)
# Remove vertical lines
vertical_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (1,25))
detect_vertical = cv2.morphologyEx(threshold, cv2.MORPH_OPEN, vertical_kernel, iterations=2)
cnts = cv2.findContours(detect_vertical, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
for c in cnts:
cv2.drawContours(image, [c], -1, (255,255,255), 5)
cv2.drawContours(denoised, [c], -1, (0, 0, 0), 5)
cv2.drawContours(threshold, [c], -1, (0, 0, 0), 5)
# Display the preprocessed image
cv2_imshow(denoised)
# Apply OCR using Tesseract
config = "--psm 7 --oem 3 -c tessedit_char_whitelist=0123456789"
text = pytesseract.image_to_string(denoised, config=config)
return text.strip()
# Read the image
image_path = '51.png'
image = cv2.imread(image_path)
# Define the region of interest (coordinates of the desired region)
x, y, w, h = 4, 4, 800, 100
# Crop the image to the defined region
roi = image[y:y+h, x:x+w]
# Recognize the handwritten digit within the cropped region
recognized_digit = recognize_digit(roi)
# Print the recognized digit
print("Recognized digit:", recognized_digit)
Подробнее здесь: https://stackoverflow.com/questions/791 ... ecognition
Распознавание рукописных чисел и текста ⇐ Python
Программы на Python
1730923368
Anonymous
Я работаю над проектом, в котором мне удалось успешно обнаружить ячейки табличного изображения, и в каждой ячейке я также пытаюсь обнаружить написанные числа и текст, но мне неоднократно удавалось это сделать, перепробовав так много вариантов. >
Здесь я прикрепил свою последнюю попытку использования pytesseract, хотя я знаю, что pytesseract не подходит для обнаружения рукописного текста. Но тем не менее он определяет 5 из 51, 79 из 71.
!apt-get install -y tesseract-ocr
from google.colab.patches import cv2_imshow
import cv2
import pytesseract
def recognize_digit(image):
# Preprocess the image for OCR
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
clahe = cv2.createCLAHE(clipLimit=0.9, tileGridSize=(8, 8))
equalized = clahe.apply(gray)
threshold = cv2.threshold(equalized, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
denoised = cv2.fastNlMeansDenoising(threshold, h=0)
# Remove horizontal lines
horizontal_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (24,1))
detect_horizontal = cv2.morphologyEx(threshold, cv2.MORPH_OPEN, horizontal_kernel, iterations=2)
cnts = cv2.findContours(detect_horizontal, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
for c in cnts:
cv2.drawContours(image, [c], -1, (255,255,255), 5)
cv2.drawContours(denoised, [c], -1, (0, 0, 0), 5)
cv2.drawContours(threshold, [c], -1, (0, 0, 0), 5)
# Remove vertical lines
vertical_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (1,25))
detect_vertical = cv2.morphologyEx(threshold, cv2.MORPH_OPEN, vertical_kernel, iterations=2)
cnts = cv2.findContours(detect_vertical, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
for c in cnts:
cv2.drawContours(image, [c], -1, (255,255,255), 5)
cv2.drawContours(denoised, [c], -1, (0, 0, 0), 5)
cv2.drawContours(threshold, [c], -1, (0, 0, 0), 5)
# Display the preprocessed image
cv2_imshow(denoised)
# Apply OCR using Tesseract
config = "--psm 7 --oem 3 -c tessedit_char_whitelist=0123456789"
text = pytesseract.image_to_string(denoised, config=config)
return text.strip()
# Read the image
image_path = '51.png'
image = cv2.imread(image_path)
# Define the region of interest (coordinates of the desired region)
x, y, w, h = 4, 4, 800, 100
# Crop the image to the defined region
roi = image[y:y+h, x:x+w]
# Recognize the handwritten digit within the cropped region
recognized_digit = recognize_digit(roi)
# Print the recognized digit
print("Recognized digit:", recognized_digit)
Подробнее здесь: [url]https://stackoverflow.com/questions/79163890/handwritten-number-and-text-recognition[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия