-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyWedg.py
126 lines (120 loc) · 6.25 KB
/
myWedg.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'untitled.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
import matplotlib.pyplot as plt
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtGui import QImage, QPixmap, qRgb
import cv2
import numpy as np
from MyGraphView import QtImageViewer
from cv2 import StereoSGBM_create
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(859, 612)
# self.graphicsView = QtWidgets.QGraphicsView(Form)
self.graphicsView = QtImageViewer(Form)
self.graphicsView.loadImageFromFile()
self.graphicsView.setGeometry(QtCore.QRect(220, 0, 641, 611))
self.graphicsView.setObjectName("graphicsView")
self.verticalLayoutWidget = QtWidgets.QWidget(Form)
self.verticalLayoutWidget.setGeometry(QtCore.QRect(0, 0, 221, 611))
self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setObjectName("verticalLayout")
self.horizontalSlider_2 = QtWidgets.QSlider(self.verticalLayoutWidget)
self.horizontalSlider_2.setOrientation(QtCore.Qt.Horizontal)
self.horizontalSlider_2.setObjectName("horizontalSlider_2")
self.verticalLayout.addWidget(self.horizontalSlider_2)
self.horizontalSlider_6 = QtWidgets.QSlider(self.verticalLayoutWidget)
self.horizontalSlider_6.setOrientation(QtCore.Qt.Horizontal)
self.horizontalSlider_6.setObjectName("horizontalSlider_6")
self.verticalLayout.addWidget(self.horizontalSlider_6)
self.horizontalSlider_7 = QtWidgets.QSlider(self.verticalLayoutWidget)
self.horizontalSlider_7.setOrientation(QtCore.Qt.Horizontal)
self.horizontalSlider_7.setObjectName("horizontalSlider_7")
self.verticalLayout.addWidget(self.horizontalSlider_7)
self.horizontalSlider_5 = QtWidgets.QSlider(self.verticalLayoutWidget)
self.horizontalSlider_5.setOrientation(QtCore.Qt.Horizontal)
self.horizontalSlider_5.setObjectName("horizontalSlider_5")
self.verticalLayout.addWidget(self.horizontalSlider_5)
self.horizontalSlider_8 = QtWidgets.QSlider(self.verticalLayoutWidget)
self.horizontalSlider_8.setOrientation(QtCore.Qt.Horizontal)
self.horizontalSlider_8.setObjectName("horizontalSlider_8")
self.verticalLayout.addWidget(self.horizontalSlider_8)
self.horizontalSlider_9 = QtWidgets.QSlider(self.verticalLayoutWidget)
self.horizontalSlider_9.setOrientation(QtCore.Qt.Horizontal)
self.horizontalSlider_9.setObjectName("horizontalSlider_9")
self.verticalLayout.addWidget(self.horizontalSlider_9)
self.horizontalSlider_4 = QtWidgets.QSlider(self.verticalLayoutWidget)
self.horizontalSlider_4.setOrientation(QtCore.Qt.Horizontal)
self.horizontalSlider_4.setObjectName("horizontalSlider_4")
self.verticalLayout.addWidget(self.horizontalSlider_4)
self.horizontalSlider_3 = QtWidgets.QSlider(self.verticalLayoutWidget)
self.horizontalSlider_3.setOrientation(QtCore.Qt.Horizontal)
self.horizontalSlider_3.setObjectName("horizontalSlider_3")
self.verticalLayout.addWidget(self.horizontalSlider_3)
self.horizontalSlider = QtWidgets.QSlider(self.verticalLayoutWidget)
self.horizontalSlider.setOrientation(QtCore.Qt.Horizontal)
self.horizontalSlider.setObjectName("horizontalSlider")
self.verticalLayout.addWidget(self.horizontalSlider)
self.win_size =1
self.stereoComputer = StereoSGBM_create(minDisparity= 5,
numDisparities = 35,
blockSize = 1,
uniquenessRatio = 1,
speckleWindowSize = 150,
speckleRange = 1,
disp12MaxDiff = 10,
mode=cv2.StereoSGBM_MODE_HH,
P1 = 5*3*self.win_size**2,#8*3*win_size**2,
P2 =10*3*self.win_size**2) #32*3*win_size**2
self.retranslateUi(Form)
self.setupComponent()
QtCore.QMetaObject.connectSlotsByName(Form)
def setupComponent(self):
self.horizontalSlider_2.valueChanged.connect(self.printvalue)
leftImg,rightImg = self.graphicsView.getImages()
disp_map = self.stereoComputer.compute(leftImg,rightImg).astype(np.uint8)
h,w=disp_map.shape
new = disp_map.copy()
image = self.numpyQImage(new)
pixmap = QPixmap.fromImage(image)
self.graphicsView.resize(h, w)
self.graphicsView.setImage(pixmap)
def numpyQImage(self,image):
qImg = QImage()
if image.dtype == np.uint8:
if len(image.shape) == 2:
channels = 1
height, width = image.shape
bytesPerLine = channels * width
qImg = QImage(
image.data, width, height, bytesPerLine, QImage.Format_Indexed8
)
qImg.setColorTable([qRgb(i, i, i) for i in range(256)])
elif len(image.shape) == 3:
if image.shape[2] == 3:
height, width, channels = image.shape
bytesPerLine = channels * width
qImg = QImage(
image.data, width, height, bytesPerLine, QImage.Format_RGB888
)
elif image.shape[2] == 4:
height, width, channels = image.shape
bytesPerLine = channels * width
fmt = QImage.Format_ARGB32
qImg = QImage(
image.data, width, height, bytesPerLine, QImage.Format_ARGB32
)
return qImg
def printvalue(self,value):
print(value)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))