You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
554 B
24 lines
554 B
import sys
|
|
import cv2
|
|
import numpy as np
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
|
def binarization(img_path, T):
|
|
img = cv2.imread(img_path, 0) # 读取图片
|
|
for i in range(0, img.shape[0]):
|
|
for j in range(0, img.shape[1]):
|
|
if img[i][j] >= T: # 阈值,可自定义
|
|
img[i][j] = 255
|
|
else:
|
|
img[i][j] = 0
|
|
cv2.imwrite('./output/binarization.jpg', img)
|
|
|
|
|
|
'''
|
|
输入:img_path,阈值
|
|
输出:二值化图片
|
|
'''
|
|
if __name__ == '__main__':
|
|
binarization(sys.argv[1], eval(sys.argv[2]))
|