OpenCV Python - Fixing Broken Text

OpenCV Python - Fixing Broken Text

I am attempting to repair broken text (the images below) so that I can perform OCR on the images. How do I go about repairing the text below? I have already tried dilation, erosion, morphology closing, and using the distance between contours. None of these seem to work. I would appreciate any help, thanks.

I am attempting to repair broken text (the images below) so that I can perform OCR on the images. How do I go about repairing the text below? I have already tried dilation, erosion, morphology closing, and using the distance between contours. None of these seem to work. I would appreciate any help, thanks.

Broken Text:

Attempted Solutions (none work):

import cv2
import pytesseract
import numpy as np

img = cv2.imread ("/Users/2020shatgiskessell/Desktop/OpenSlate/FN2.png")

def OCR (img): config = ('-l eng --oem 1 --psm 3') text = pytesseract.image_to_string(img, config = config) return text

def get_countour(img): try: output = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) output = output.copy() except Exception: output = img.copy() #imgray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) #ret, thresh = cv2.threshold(output, 127, 255, 0) contours, hierarchy = cv2.findContours(output, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) c = max(contours, key = cv2.contourArea) contours.remove(c) cv2.drawContours(output, contours, -1, (0,255,0),-1)

    kernel = np.ones((2,1),np.uint8)
    #eroded = cv2.erode(output, kernel,1)
    output = cv2.dilate(output, kernel,1)
    return output

def strengthen(img): try: imgray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) except Exception: imgray = img #ret, thresh = cv2.threshold(imgray,0,255,cv2.THRESH_BINARY | cv2.THRESH_OTSU) #blur1 = cv2.blur(imgray,(5,5)) blur2 = cv2.GaussianBlur(imgray,(5,5),0) thresh2 = cv2.adaptiveThreshold(blur2, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 31, 2) kernel = np.ones((2,1),np.uint8) #eroded = cv2.erode(thresh2, kernel,1) #opening = cv2.morphologyEx(eroded, cv2.MORPH_CLOSE, kernel) #closing = cv2.morphologyEx(opening, cv2.MORPH_CLOSE, kernel) return thresh2

#MNIST(img) strengthened= strengthen(img)

contours = get_countour(strengthened)

print("from morphology transformation: "+ OCR(contours))

cv2.imshow('img', img) cv2.imshow('contour', contours)

cv2.waitKey(0) cv2.destroyAllWindows()

The above images are recognized as:

Image 1: (CAN ajne oF

Image 2: > AMAR VRAIR

Image 3: STure

python opencv

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Create a Virtual Pen and Eraser with Python OpenCV - Genial Code

Learn Free how to create a virtual pen and eraser with python and OpenCV with source code and complete guide. This entire application is built fundamentally on contour detection. It can be thought of as something like closed color curves on compromises that have the same color or intensity, it's like a blob. In this project we use color masking to get the binary mask of our target color pen, then we use the counter detection to find the location of this pen and the contour to find it.

OpenCV Python | Python OpenCV Tutorial | Python for Beginners

OpenCV Python in Python will explain all the basics of OpenCV. It also explains how to create a face recognition system and a motion detector.

Basic Data Types in Python | Python Web Development For Beginners

In the programming world, Data types play an important role. Each Variable is stored in different data types and responsible for various functions. Python had two different objects, and They are mutable and immutable objects.

How To Compare Tesla and Ford Company By Using Magic Methods in Python

Magic Methods are the special methods which gives us the ability to access built in syntactical features such as ‘<’, ‘>’, ‘==’, ‘+’ etc.. You must have worked with such methods without knowing them to be as magic methods. Magic methods can be identified with their names which start with __ and ends with __ like __init__, __call__, __str__ etc. These methods are also called Dunder Methods, because of their name starting and ending with Double Underscore (Dunder).

OpenCV Python Tutorial: Computer Vision With OpenCV In Python

OpenCV Python Tutorial: Computer Vision With OpenCV In Python: Learn Vision Includes all OpenCV Image Processing Features with Simple Examples. Face Detection, Face Recognition. Computer Vision is an AI based, that is, Artificial Intelligence based technology that allows computers to understand and label images. Use OpenCV to work with image files. Create Face Detection Software. Detect Objects, including corner, edge, and grid detection techniques with OpenCV and Python. Use Python and Deep Learning to build image classifiers. Use Python and OpenCV to draw shapes on images and videos. Create Color Histograms with OpenCV