-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtextFromImage.py
More file actions
40 lines (29 loc) · 1.02 KB
/
textFromImage.py
File metadata and controls
40 lines (29 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import cv2 as cv
import pytesseract
def getTextFromImg(image, blurStrength = 1):
#image = get_grayscale(image)
#image = thresholding(image)
#image = remove_noise(image, blurStrength)
return ocr_core(image)
def getImgPreproccessing(image, blurStrength):
image = get_grayscale(image)
#image = thresholding(image)
#image = remove_noise(image, blurStrength)
#image = get_canny(image)
return image
def ocr_core(img):
text = pytesseract.image_to_string(img)
return text
def get_grayscale(image):
return cv.cvtColor(image, cv.COLOR_BGR2GRAY)
def remove_noise(image, blurStrng):
return cv.blur(image, (blurStrng,blurStrng))
def thresholding(image):
return cv.threshold(image, 0, 25, cv.THRESH_BINARY + cv.THRESH_OTSU)[1]
def get_canny(image):
return cv.Canny(image, 174, 175)
def returnWhite(image):
gray = cv.cvtColor(image,cv.COLOR_BGR2GRAY)
mask = cv.inRange(image,(255,255,255),(238, 238, 238))
mask_rgb = cv.cvtColor(mask,cv.COLOR_GRAY2BGR)
return mask_rgb