如何使用 opencv 将一系列灰色像素转换为黑色?
How to convert a range of gray pixels to black with opencv?
我正在使用 OpenCV 和 Tesseract。我试图将一系列灰色像素转换为黑色。例子:
如您所见,有一个“明亮的”多重灰色,我需要将其转换为全黑以便 OCR 能够更好地读取它。
有人知道怎么做吗?
import cv2
import numpy as np I = cv2.imread('imgPath')
## If you are interested in thresholding based on brightness,
## using grey channel or brightness channel from HSV is always a good idea :)
# Convert input RGB to HSV
HSV = cv2.cvtColor(I, cv2.COLOR_BGR2HSV)
# Get brightness channel
V = HSV[:, :, 2]
# Threshold all the very bright pixels
bw = 255*np.uint8(V < 200)
# save the image you want
cv2.imwrite("bw.png", bw)
我正在使用 OpenCV 和 Tesseract。我试图将一系列灰色像素转换为黑色。例子:
如您所见,有一个“明亮的”多重灰色,我需要将其转换为全黑以便 OCR 能够更好地读取它。
有人知道怎么做吗?
import cv2
import numpy as np I = cv2.imread('imgPath')
## If you are interested in thresholding based on brightness,
## using grey channel or brightness channel from HSV is always a good idea :)
# Convert input RGB to HSV
HSV = cv2.cvtColor(I, cv2.COLOR_BGR2HSV)
# Get brightness channel
V = HSV[:, :, 2]
# Threshold all the very bright pixels
bw = 255*np.uint8(V < 200)
# save the image you want
cv2.imwrite("bw.png", bw)