0

This is the picture

I want to get rid of the black border around inorder to enhance ocr prediction. How to eliminate it? this is my code so far.

image = cv2.imread(filename)
cv2.resize(image,(416,416))
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
img_lp = cv2.resize(gray, (333, 75))
#img_gray_lp = cv2.cvtColor(img_lp, cv2.COLOR_BGR2GRAY)
_, img_binary_lp = cv2.threshold(img_lp, 200, 255, 
cv2.THRESH_BINARY+cv2.THRESH_OTSU)
img_binary_lp = cv2.erode(img_binary_lp, (3,3))
img_binary_lp = cv2.dilate(img_binary_lp, (3,3))
cv2.floodFill(img_binary_lp, None, (0,0), 255)
LP_WIDTH = img_binary_lp.shape[0]
LP_HEIGHT = img_binary_lp.shape[1]

# Make borders white
img_binary_lp[0:3,:] = 255
img_binary_lp[:,0:3] = 255
img_binary_lp[72:75,:] = 255
img_binary_lp[:,330:333] = 255

#Estimations of character contours sizes of cropped license plates
dimensions = [LP_WIDTH/6,
                   LP_WIDTH/2,
                   LP_HEIGHT/10,
                   2*LP_HEIGHT/3]

plt.imshow(img_binary_lp, cmap='gray')

if i tried flood fill it removes certain initial letters in certain images like this after flood fill which removes certain letters

The original image of the above is original image which removes certain letters in floodfill

devansh
  • 13
  • 3
  • 2
    Flood fill with white at seed point `(0, 0)`. Assuming OpenCV for Python, and some grayscale image: `cv2.floodFill(img, None, (0, 0), 255)`. Won't get rid of the small black parts bottom right, but should be sufficient for further OCR, I guess. – HansHirse Aug 24 '21 at 10:27
  • @HansHirse I tried floodfill but it results in removing few initial letters in certain images. – devansh Aug 24 '21 at 11:05
  • Please provide the original input image. – HansHirse Aug 24 '21 at 11:08
  • @HansHirse I've added the original image – devansh Aug 24 '21 at 11:14
  • `cv2.floodFill(img_binary_lp, None, (4, 4), 255)` AFTER making the borders white. – HansHirse Aug 24 '21 at 11:18
  • still the output is same as before. – devansh Aug 24 '21 at 11:22
  • Which output? The image (show your updated code) - or the result of the later (and still not shown) OCR? – HansHirse Aug 24 '21 at 11:25
  • cv2.floodFill(img_binary_lp, None, (4, 4), 255) i've added this line after cv2.floodFill(img_binary_lp, None, (0,0), 255) line in the above code. The output image is same it removes initial letters as shown above. – devansh Aug 24 '21 at 11:31
  • Remove `cv2.floodFill(img_binary_lp, None, (0, 0), 255)`, and add `cv2.floodFill(img_binary_lp, None, (4, 4), 255)` after `img_binary_lp[:,330:333] = 255`..... (I won't further support here.....) – HansHirse Aug 24 '21 at 11:34

0 Answers0