-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyside_test.py
57 lines (37 loc) · 1.19 KB
/
pyside_test.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
import sys
from PySide.QtCore import *
from PySide.QtGui import *
import numpy as np
from sw.vision.camera import Camera
cam = Camera(320, 240, id=0)
app = QApplication(sys.argv)
class ImageView(QWidget):
def __init__(self, shape, parent=None):
super(ImageView, self).__init__(parent)
self.image = np.zeros(shape, dtype=np.uint8)
height, width, byteValue = self.image.shape
byteValue = byteValue * width
self.setFixedSize(width, height)
self.mQImage = QImage(self.image.data, width, height, byteValue, QImage.Format_RGB888)
def paintEvent(self, QPaintEvent):
painter = QPainter()
painter.begin(self)
painter.drawImage(0, 0, self.mQImage)
painter.end()
def setImage(self, im):
self.image[:] = im
self.repaint()
wid = QWidget()
wid.setWindowTitle('Simple')
image_view = ImageView(shape=cam.shape + (3,))
refresh_button = QPushButton("test")
@refresh_button.clicked.connect
def on_click():
image_view.setImage(cam.read())
image_view.setImage(cam.read())
layout = QVBoxLayout()
layout.addWidget(image_view)
layout.addWidget(refresh_button)
wid.setLayout(layout)
wid.show()
sys.exit(app.exec_())