<p>You can use a deep learning based text detector called <a href="https://arxiv.org/abs/1704.03155" rel="nofollow noreferrer">Efficient and Accurate Scene Text - EAST</a>. It can be used with OpenCV functions but first you need to download the trained model from <a href="https://github.com/YCICI/EAST-OpenCv" rel="nofollow noreferrer">frozen_east_text_detection.pb</a></p>
<p>The following code and its comments was borrowed in its entirety from <a href="https://github.com/YCICI/EAST-OpenCv/blob/master/text_detection.py" rel="nofollow noreferrer">here -<code>text_detection.py</code></a>. Remember to pass the downloaded <code>.pb</code> file into <code>cv2.dnn.readNet()</code></p>
<p><em><strong>Highlights:</strong></em></p>
<ul>
<li>The trained model is passed into <code>cv2.dnn.readNet()</code> as a <code>.pb</code> file.</li>
<li>This model only accepts images of dimensions which are a multiple of 32. (Here we set the width and height of the input image to 320 by default.)</li>
<li>Two output layers are defined in <code>layerNames</code> each for probabilities of containing text and bounding box coordinates</li>
<li>We cannot pass an image we normally do to every OpenCV function into a model. Every image passed into <code>cv2.dnn.blobFromImage()</code> where the image is considered to be a <strong>blob</strong>. It undergoes <strong>mean subtraction</strong>, <strong>scaling</strong> and <strong>channel swapping</strong>. <a href="https://pyimagesearch.com/2017/11/06/deep-learning-opencvs-blobfromimage-works/" rel="nofollow noreferrer">more details on these here</a></li>
<li>The input blob is passed to <code>net.setInput()</code> along with the output layers.</li>
<li>The output is a tuple of scores containing:
<ul>
<li>the probability of whether a region is text or not</li>
<li>the bounding box coordinate of the text region</li>
</ul>
</li>
<li>We filter out predictions below a certain probability</li>
<li>On the remaining predictions we perform non-maximal suppression to remove overlapping boxes</li>
</ul>
<p>For more code explanation <a href="https://pyimagesearch.com/2018/08/20/opencv-text-detection-east-text-detector/" rel="nofollow noreferrer">Please refer here</a></p>
<p><em><strong>Code:</strong></em></p>
<pre><code>image = cv2.imread('path_to_image')
orig = image.copy()
(H, W) = image.shape[:2]

# set the new width and height and then determine the ratio in change
# for both the width and height
(newW, newH) = (320, 320)
rW = W / float(newW)
rH = H / float(newH)

# resize the image and grab the new image dimensions
image = cv2.resize(image, (newW, newH))
(H, W) = image.shape[:2]

# define the two output layer names for the EAST detector model that
# we are interested -- the first is the output probabilities and the
# second can be used to derive the bounding box coordinates of text
layerNames = [
    &quot;feature_fusion/Conv_7/Sigmoid&quot;,
    &quot;feature_fusion/concat_3&quot;]

# load the pre-trained EAST text detector
print(&quot;[INFO] loading EAST text detector...&quot;)
net = cv2.dnn.readNet('path_containing_frozen_east_text_detection.pb')

# construct a blob from the image and then perform a forward pass of
# the model to obtain the two output layer sets
blob = cv2.dnn.blobFromImage(image, 1.0, (W, H),(123.68, 116.78, 103.94), swapRB=True, crop=False)
net.setInput(blob)
(scores, geometry) = net.forward(layerNames)

# grab the number of rows and columns from the scores volume, then
# initialize our set of bounding box rectangles and corresponding
# confidence scores
(numRows, numCols) = scores.shape[2:4]
rects = []
confidences = []

# loop over the number of rows
for y in range(0, numRows):
    # extract the scores (probabilities), followed by the geometrical
    # data used to derive potential bounding box coordinates that
    # surround text
    scoresData = scores[0, 0, y]
    xData0 = geometry[0, 0, y]
    xData1 = geometry[0, 1, y]
    xData2 = geometry[0, 2, y]
    xData3 = geometry[0, 3, y]
    anglesData = geometry[0, 4, y]
    
    for x in range(0, numCols):
        # ignore probability values below 0.75
        if scoresData[x] &lt; 0.75:
            continue
        
        # compute the offset factor as our resulting feature maps will
        # be 4x smaller than the input image
        (offsetX, offsetY) = (x * 4.0, y * 4.0)
        
        # extract the rotation angle for the prediction and then
        # compute the sin and cosine
        angle = anglesData[x]
        cos = np.cos(angle)
        sin = np.sin(angle)
        
        # use the geometry volume to derive the width and height of
        # the bounding box
        h = xData0[x] + xData2[x]
        w = xData1[x] + xData3[x]
        
        # compute both the starting and ending (x, y)-coordinates for
        # the text prediction bounding box
        endX = int(offsetX + (cos * xData1[x]) + (sin * xData2[x]))
        endY = int(offsetY - (sin * xData1[x]) + (cos * xData2[x]))
        startX = int(endX - w)
        startY = int(endY - h)
        
        # add the bounding box coordinates and probability score to
        # our respective lists
        rects.append((startX, startY, endX, endY))
        confidences.append(scoresData[x])

# apply non-maxima suppression to suppress weak, overlapping bounding
# boxes
boxes = non_max_suppression(np.array(rects), probs=confidences)

# loop over the bounding boxes
for (startX, startY, endX, endY) in boxes:
    # scale the bounding box coordinates based on the respective
    # ratios
    startX = int(startX * rW)
    startY = int(startY * rH)
    endX = int(endX * rW)
    endY = int(endY * rH)
    # draw the bounding box on the image
    cv2.rectangle(orig, (startX, startY), (endX, endY), (0, 255, 0), 2)

cv2.imwrite('path_to_save', orig)
</code></pre>
<p><em><strong>Result:</strong></em></p>
<p><a href="https://i.stack.imgur.com/MDZIm.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MDZIm.jpg" alt="enter image description here" /></a></p>
<p>Although the result is not as expected, it is pretty close</p>
<p><strong>UPDATE:</strong></p>
<p>To crop and save each individual bounding box as an image do the following:</p>
<pre><code># take a copy o the original image
image2 = orig.copy()
for i, (startX, startY, endX, endY) in enumerate(boxes):
    startX = int(startX * rW)
    startY = int(startY * rH)
    endX = int(endX * rW)
    endY = int(endY * rH)
    cropped = image2[startY:endY, startX:endX]
    cv2.imwrite(r'Cropped_result\crop_img_{}.jpg'.format(i), cropped)
</code></pre>
Detect text region in image using Opencv
<p>I have an image and want to detect the text regions in it. </p>

<p>I tried TiRG_RAW_20110219 project but the results are not satisfactory. If the input image is <a href="https://imgur.com/yCxOvQS,GD38rCa" rel="noreferrer">http://imgur.com/yCxOvQS,GD38rCa</a> it is producing <a href="https://imgur.com/yCxOvQS,GD38rCa#1" rel="noreferrer">http://imgur.com/yCxOvQS,GD38rCa#1</a> as output. </p>

<p>Can anyone suggest some alternative. I wanted this to improve the output of tesseract by sending it only the text region as input.</p>