1
|
|
2
|
|
3
|
|
4
|
|
5
|
import argparse
|
6
|
import os
|
7
|
import cv2
|
8
|
import numpy as np
|
9
|
|
10
|
|
11
|
|
12
|
def oimage_read_from_chinese_path(ppath,ThresholdType,Threshold,MaxValue):
|
13
|
image_numpy_data = cv2.imdecode(np.fromfile(ppath, dtype=np.uint8), 0)
|
14
|
|
15
|
if ThresholdType == 1:
|
16
|
ret, thresh1 = cv2.threshold(image_numpy_data, Threshold, MaxValue, cv2.THRESH_BINARY)
|
17
|
return thresh1
|
18
|
elif ThresholdType == 2:
|
19
|
ret, thresh2 = cv2.threshold(image_numpy_data, Threshold, MaxValue, cv2.THRESH_BINARY_INV)
|
20
|
return thresh2
|
21
|
elif ThresholdType == 3:
|
22
|
ret, thresh3 = cv2.threshold(image_numpy_data, Threshold, MaxValue, cv2.THRESH_TRUNC)
|
23
|
return thresh3
|
24
|
elif ThresholdType == 4:
|
25
|
ret, thresh4 = cv2.threshold(image_numpy_data, Threshold, MaxValue, cv2.THRESH_TOZERO)
|
26
|
return thresh4
|
27
|
elif ThresholdType == 5:
|
28
|
ret, thresh5 = cv2.threshold(image_numpy_data, Threshold, MaxValue, cv2.THRESH_TOZERO_INV)
|
29
|
return thresh5
|
30
|
|
31
|
|
32
|
def print_hi(imgpath,ThresholdType,Threshold,MaxValue):
|
33
|
|
34
|
img_path = oimage_read_from_chinese_path(imgpath,ThresholdType,Threshold,MaxValue)
|
35
|
|
36
|
cv2.imwrite("OutImage.bmp", img_path)
|
37
|
|
38
|
|
39
|
|
40
|
if __name__ == '__main__':
|
41
|
parser = argparse.ArgumentParser()
|
42
|
parser.add_argument("--ImagePath", type=str, required=True)
|
43
|
parser.add_argument("--ThresholdType", type=int, required=True)
|
44
|
parser.add_argument("--Threshold", type=int, required=True)
|
45
|
parser.add_argument("--MaxValue", type=int, default=255)
|
46
|
args = parser.parse_args()
|
47
|
print_hi(args.ImagePath,args.ThresholdType,args.Threshold,args.MaxValue)
|
48
|
|
49
|
|