Is it possible to enlarge the upper margin of the image, keeping the background the same color? I have tried cv2 and pillow, but could not. It is to improve the scraping of image web pages with scrapy and tesseract in python
from PIL import Image
import pytesseract
import imutils
import cv2
import numpy as np
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract'
url = "https://www.yapo.cl/pg/0lu3quB3xJWOOJl5r7RBle3TME2kepf9ahuvYSfPYiA==.gif"
img = Image.open(urllib.request.urlopen(url))
img.save("image.png")
image = cv2.imread("image.png",0)
image = imutils.resize(image, width=400)
cv2.imshow('thresh', image)
cv2.waitKey()
kernel = np.ones((2,2), np.uint8)
cv2.imshow('thresh', image)
cv2.waitKey()
image = cv2.erode(image, kernel, iterations=1)
cv2.imshow('thresh', image)
cv2.waitKey()
image = cv2.dilate(image, kernel, iterations=1)
cv2.imshow('thresh', image)
cv2.waitKey()
image = cv2.GaussianBlur(image, (7,7), 0)
#result = 255 - thresh
image = cv2.threshold(image, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
phone = pytesseract.image_to_string(image, config="-c tessedit_char_whitelist=0123456789+() --psm 6").strip()
print(phone)