簡體   English   中英

如何使用 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)  

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM