-
Notifications
You must be signed in to change notification settings - Fork 10
/
callEnhance.py
104 lines (79 loc) · 3.47 KB
/
callEnhance.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 17 16:26:13 2020
@author: cherish
"""
import sys,fitz
from PyQt5.QtWidgets import QApplication, QDialog, QFileDialog
from enhanceFunctions import *
from enhance_UI import Ui_Enhance_Dialog
class EnhanceForm(QDialog):
def __init__(self):
super().__init__()
self.ui = Ui_Enhance_Dialog()
self.ui.setupUi(self)
self.colorValue = 1.0
self.contrastValue = 2.0
self.sharpnessValue = 1.0
self.brightnessValue = 1.0
self.saveFlag = False
self.ui.pushButton_w2_openPDF.clicked.connect(self.w2_openPDF)
self.ui.Slider_w2_colorSet.sliderMoved.connect(self.w2_colorValue)
self.ui.Slider_w2_contrastSet.sliderMoved.connect(self.w2_contrastValue)
self.ui.Slider_w2_sharpnessSet.sliderMoved.connect(self.w2_sharpnessValue)
self.ui.Slider_w2_brightnessSet.sliderMoved.connect(self.w2_brightnessValue)
self.ui.checkBox_w2_saveAllImage.stateChanged.connect(self.w2_saveOption)
self.ui.pushButton_w2_start.clicked.connect(self.w2_start)
self.show()
# w2 means windows 2
def w2_openPDF(self):
file_name = QFileDialog.getOpenFileName(self,
'Open File',
"/Users/user_name/Desktop/",
"PDF Files (*.pdf)")
# print(type(file_name))
self.ui.lineEdit_w2_openPDF.setText(file_name[0])
self.ui.label_w2_tips.setText("请设置增强因子后,按开始处理按钮\n1.0表示原始图像")
def w2_colorValue(self, value):
self.colorValue = value / 10.0
self.ui.label_w2_colorValue.setText(str(value / 10.0))
def w2_contrastValue(self, value):
self.contrastValue = value / 10.0
self.ui.label_w2_contrastValue.setText(str(value / 10.0))
def w2_sharpnessValue(self, value):
self.sharpnessValue = value / 10.0
self.ui.label_w2_sharpnessValue.setText(str(value / 10.0))
def w2_brightnessValue(self, value):
self.brightnessValue = value / 10.0
self.ui.label_w2_brightnessValue.setText(str(value / 10.0))
def w2_saveOption(self):
self.saveFlag = False
if self.ui.checkBox_w2_saveAllImage.isChecked():
self.saveFlag = True
def w2_start(self):
oldFileName = self.ui.lineEdit_w2_openPDF.text()
newFileName = oldFileName.replace(".pdf", "[enhanced].pdf")
if oldFileName != '':
doc = fitz.open(oldFileName)
toc=doc.getToC()
enhanceDoc = fitz.open()
num = doc.pageCount
baseBar = 1.0 / num * 100
for i in range(num):
imgpdf = getEnhancedPdf(doc[i], i, self.saveFlag,
[self.colorValue, self.contrastValue, self.sharpnessValue,
self.brightnessValue], 2)
enhanceDoc.insertPDF(imgpdf)
self.ui.label_w2_tips.setText("正在处理第 %d 页" % i)
self.ui.progressBar_w2.setValue(i * baseBar)
enhanceDoc.setToC(toc)
enhanceDoc.save(newFileName)
doc.close()
enhanceDoc.close()
self.ui.progressBar_w2.setValue(100)
self.ui.label_w2_tips.setText("处理完毕")
if __name__ == "__main__":
app = QApplication(sys.argv)
w = EnhanceForm()
w.show()
sys.exit(app.exec_())