M
M
maryaturova2020-06-12 18:24:13
Python
maryaturova, 2020-06-12 18:24:13

Cut pictures how?

Dear colleagues!
The question arose with the cutting of words from the picture. Decided to try opencv.

# ОТКРЫВАЕМ КАРТИНКУ
    imge = cv2.imread(image_file, cv2.IMREAD_GRAYSCALE)
  
    # УВЕЛИЧИВАЕМ РАЗМЕР КАРТИНКИ
    scale_percent =  250  # percent of original size
    width =  int(imge.shape[1] * scale_percent / 100)
    height =  int(imge.shape[0] * scale_percent / 100)
    dim = (width, height)
    img =  cv2.resize( imge, dim, interpolation =  cv2.INTER_AREA)

    #РАЗМЫТИЕ ПО ГАУССУ
    blur = cv2.GaussianBlur(img, (5, 5), 0)
  
    #ВОЗВРАЩАЕМ В ЧЕРНО-БЕЛОЕ
    ret, thresh = cv2.threshold(blur, 61, 255, 1)

After the above manipulations, I get such a picture
5ee39cd43665b006422813.png
. The next step is to cut the picture into words.
It only comes to mind to determine that there is a large distance between the black pixels, and to cut it according to the average value.
In words, it’s simple, but how to implement the darkness is not enough.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question