1 | initial version |
I solved problem.
#!/usr/bin/python37
#OpenCV 4.1.2-pre, THonny IDE
#Raspberry pi 3/4
#Date: 31 October, 2019
import cv2
import numpy as np
## Read
img = cv2.imread('handwriting.jpg')
## convert to hsv
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
mask = cv2.inRange(hsv, (70, 25, 25), (140, 255,255))
## slice the black
imask = mask>0
mask_black = np.zeros_like(img, np.uint8)
mask_black[imask] = img[imask]
## save
cv2.imwrite('handwriting_1.jpg', mask_black)
Output:
2 | No.2 Revision |
I solved problem.problem. You don't needed threshold
. Used cv2.InRange
will suit your need.
#!/usr/bin/python37
#OpenCV 4.1.2-pre, THonny IDE
#Raspberry pi 3/4
#Date: 31 October, 2019
import cv2
import numpy as np
## Read
img = cv2.imread('handwriting.jpg')
## convert to hsv
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
mask = cv2.inRange(hsv, (70, 25, 25), (140, 255,255))
## slice the black
imask = mask>0
mask_black = np.zeros_like(img, np.uint8)
mask_black[imask] = img[imask]
## save
cv2.imwrite('handwriting_1.jpg', mask_black)
Output:
3 | No.3 Revision |
I solved problem. You don't needed threshold
. Used cv2.InRange
will suit your need.
#!/usr/bin/python37
#OpenCV 4.1.2-pre, THonny IDE
#Raspberry pi 3/4
#Date: 31 October, 2019
import cv2
import numpy as np
## Read
img = cv2.imread('handwriting.jpg')
## convert to hsv
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
mask = cv2.inRange(hsv, (70, 25, 25), (140, 255,255))
## slice the black
imask = mask>0
mask_black = np.zeros_like(img, np.uint8)
mask_black[imask] = img[imask]
## save
cv2.imwrite('handwriting_1.jpg', mask_black)
Output:
I can't go further. You cannot get bold. The pay slip is little visible about 25. Because of that it is black.
#!/usr/bin/python37
#OpenCV 4.1.2-pre, THonny IDE
#Raspberry pi 3/4
#Date: 31 October, 2019
import cv2
import numpy as np
## Read
img = cv2.imread('handwriting.jpg')
## convert to hsv
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
mask = cv2.inRange(hsv, (100, 15, 15), (190, 165,165))
## slice the black
imask = mask>0
mask_black = np.zeros_like(img, np.uint8)
mask_black[imask] = img[imask]
## save
cv2.imwrite('handwriting_2.jpg', mask_black)
Output:
4 | No.4 Revision |
I solved problem. You don't needed threshold
. Used cv2.InRange
will suit your need.
#!/usr/bin/python37
#OpenCV 4.1.2-pre, THonny IDE
#Raspberry pi 3/4
#Date: 31 October, 2019
import cv2
import numpy as np
## Read
img = cv2.imread('handwriting.jpg')
## convert to hsv
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
mask = cv2.inRange(hsv, (70, 25, 25), (140, 255,255))
## slice the black
imask = mask>0
mask_black = np.zeros_like(img, np.uint8)
mask_black[imask] = img[imask]
## save
cv2.imwrite('handwriting_1.jpg', mask_black)
Output:
I can't go further. You cannot get bold. The pay slip is little visible about 25. 25%. Because of that it is black.
#!/usr/bin/python37
#OpenCV 4.1.2-pre, THonny IDE
#Raspberry pi 3/4
#Date: 31 October, 2019
import cv2
import numpy as np
## Read
img = cv2.imread('handwriting.jpg')
## convert to hsv
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
mask = cv2.inRange(hsv, (100, 15, 15), (190, 165,165))
## slice the black
imask = mask>0
mask_black = np.zeros_like(img, np.uint8)
mask_black[imask] = img[imask]
## save
cv2.imwrite('handwriting_2.jpg', mask_black)
Output: