python pytesseract int

Solutions on MaxInterview for python pytesseract int by the best coders in the world

showing results for - "python pytesseract int"
Linus
22 Aug 2020
1import cv2
2import numpy as np
3
4img = cv2.imread('image.jpg')
5
6# get grayscale image
7def get_grayscale(image):
8    return cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
9
10# noise removal
11def remove_noise(image):
12    return cv2.medianBlur(image,5)
13 
14#thresholding
15def thresholding(image):
16    return cv2.threshold(image, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
17
18#dilation
19def dilate(image):
20    kernel = np.ones((5,5),np.uint8)
21    return cv2.dilate(image, kernel, iterations = 1)
22    
23#erosion
24def erode(image):
25    kernel = np.ones((5,5),np.uint8)
26    return cv2.erode(image, kernel, iterations = 1)
27
28#opening - erosion followed by dilation
29def opening(image):
30    kernel = np.ones((5,5),np.uint8)
31    return cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel)
32
33#canny edge detection
34def canny(image):
35    return cv2.Canny(image, 100, 200)
36
37#skew correction
38def deskew(image):
39    coords = np.column_stack(np.where(image > 0))
40    angle = cv2.minAreaRect(coords)[-1]
41     if angle < -45:
42        angle = -(90 + angle)
43    else:
44        angle = -angle
45    (h, w) = image.shape[:2]
46    center = (w // 2, h // 2)
47    M = cv2.getRotationMatrix2D(center, angle, 1.0)
48    rotated = cv2.warpAffine(image, M, (w, h), flags=cv2.INTER_CUBIC, borderMode=cv2.BORDER_REPLICATE)
49    return rotated
50
51#template matching
52def match_template(image, template):
53    return cv2.matchTemplate(image, template, cv2.TM_CCOEFF_NORMED) 
54