forked from docPhil99/opencvQtdemo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRe-IdImage.py
More file actions
73 lines (51 loc) · 2.02 KB
/
Re-IdImage.py
File metadata and controls
73 lines (51 loc) · 2.02 KB
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
import sys
import cv2
from PyQt5 import QtWidgets, QtGui, QtCore
from PyQt5.QtWidgets import QWidget, QApplication, QToolTip, QLabel, QVBoxLayout, QHBoxLayout, QPushButton
from PyQt5.QtGui import QFont, QPixmap, QImage, QColor
from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QObject
class ImageLoad(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def resizeEvent(self, event):
geo = self.geometry()
w1 = geo.width()*0.90
h1 = geo.height()*0.90
self.targetimage.resize(w1, h1)
query_qt = self.convert_cv_qt(self.query_cv)
self.targetimage.setPixmap(query_qt)
print(geo)
def initUI(self):
print('init')
self.setGeometry(500, 500, 940, 880)
self.setWindowTitle('Load a query image')
self.targetimage = QLabel(self)
self.textlabel = QLabel('query')
#pixmap = QPixmap('polecat.jpg')
#self.targetimage.setPixmap(pixmap)
#self.resize(pixmap.width(), pixmap.height())
ver_frame = QVBoxLayout()
ver_frame.addWidget(self.targetimage)
h_frame = QHBoxLayout()
ver_frame.addLayout(h_frame)
h_frame.addWidget(self.textlabel)
button1 = QPushButton('hi')
h_frame.addWidget(button1)
self.setLayout(ver_frame)
self.query_cv = cv2.imread('polecat.jpg')
query_qt = self.convert_cv_qt(self.query_cv)
self.targetimage.setPixmap(query_qt)
def convert_cv_qt(self, query_cv):
color_image = cv2.cvtColor(query_cv, cv2.COLOR_BGR2RGB)
h, w, ch = color_image.shape
bytes_per_line = ch * w
convert_to_qt_format = QtGui.QImage(color_image.data, w, h, bytes_per_line, QtGui.QImage.Format_RGB888)
pic = convert_to_qt_format.scaled(self.targetimage.width(), self.targetimage.height(), Qt.KeepAspectRatio)
return QPixmap.fromImage(pic)
#self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = ImageLoad()
ex.show()
sys.exit(app.exec_())