-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathimage.py
28 lines (20 loc) · 889 Bytes
/
image.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# !/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
from PIL import Image, ImageFilter
class ImageRecognitionWordProcessing(object):
@staticmethod
def process_image():
kitten = Image.open("files/Snipaste_2022-04-06_10-36-03.png")
blurryKitten = kitten.filter(ImageFilter.GaussianBlur)
blurryKitten.save("files/Snipaste_2022-04-06_10-36-03_new.png")
blurryKitten.show()
@staticmethod
def clean_file(file_path, new_file_path):
image = Image.open(file_path)
# 对图片进行阈值过滤,然后保存
image = image.point(lambda x: 0 if x < 180 else 255)
image.save(new_file_path)
if __name__ == '__main__':
ImageRecognitionWordProcessing().clean_file(os.path.join(os.getcwd(), "files/test-text_has_symbol.max_340x194.jpg"),
"text_2_clean.png")