Search code examples
pythonopencvimage-processingimage-segmentationimage-manipulation

calculate the height of character from binarization image OpenCV python


Hello i need to calculate the height of a character from a binarzation image ( see the image bellow):

Binarization image of B


Solution

  • You can calculate the row of pixels that have the most black pixels.

    import cv2
    import numpy as np
    
    pic = cv2.imread('binarized.png')[:, 50:-50, 0]
    
    np.max(np.sum(1 - (pic//255), axis=0))
    
    382
    

    Using MS Paint, I was able to confirm that the height is 382 by drawing a 382 pixel line next to it. I had to exclude your black borders though. enter image description here