You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

niblack_thresholding.py 643 B

8 years ago
1234567891011121314151617181920
  1. import cv2
  2. import numpy as np
  3. from skimage.filters import (threshold_otsu, threshold_niblack,
  4. threshold_sauvola)
  5. def niBlackThreshold( src, blockSize, k, binarizationMethod= 0 ):
  6. mean = cv2.boxFilter(src,cv2.CV_32F,(blockSize, blockSize),borderType=cv2.BORDER_REPLICATE)
  7. sqmean = cv2.sqrBoxFilter(src, cv2.CV_32F, (blockSize, blockSize), borderType = cv2.BORDER_REPLICATE)
  8. variance = sqmean - (mean*mean)
  9. stddev = np.sqrt(variance)
  10. thresh = mean + stddev * float(-k)
  11. thresh = thresh.astype(src.dtype)
  12. k = (src>thresh)*255
  13. k = k.astype(np.uint8)
  14. return k
  15. # cv2.imshow()

高性能开源中文车牌识别框架