Ask Your Question

Revision history [back]

click to hide/show revision 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: handwriting

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: handwriting

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: handwriting

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: handwriting

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: handwriting

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: handwriting