-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselect_stereo.py
146 lines (114 loc) · 4.83 KB
/
select_stereo.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import sys
import cv2
from PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout, QVBoxLayout, QPushButton, QLabel
from PyQt5.QtGui import QPixmap, QImage
from PyQt5.QtCore import QTimer
from utils import cleanfile,delete_pic
import glob
from calibration.undistort import undistort
class StereoWindow(QWidget):
def __init__(self):
super().__init__()
self.initUI()
self.num = 0
self.imagesRight = sorted(glob.glob('calibration/img_calib/img_fisheye_stereo/*.png'))
self.imagesLeft = sorted(glob.glob('calibration/img_calib/img_infra_stereo/*.png'))
self.deleteRight=[]
self.deleteLeft=[]
self.overlayDelete = cv2.imread('deleted.png')
self.upd=1
def initUI(self):
# Create a layout for the buttons on the left
vbox1 = QVBoxLayout()
button0 = QPushButton('Previous')
button0.clicked.connect(self.previous)
button1 = QPushButton('Next')
button1.clicked.connect(self.next)
button2 = QPushButton('Delete')
button2.clicked.connect(self.delete)
button3 = QPushButton('Undelete')
button3.clicked.connect(self.undo)
button4 = QPushButton('Validate selection')
button4.clicked.connect(self.validate)
vbox1.addWidget(button0)
vbox1.addWidget(button1)
vbox1.addWidget(button2)
vbox1.addWidget(button3)
vbox1.addWidget(button4)
# Create a layout for the video flux spaces
hbox2 = QHBoxLayout()
self.label1 = QLabel(self)
self.label2 = QLabel(self)
hbox2.addWidget(self.label1)
hbox2.addWidget(self.label2)
# Create a layout to combine the buttons and video flux spaces
hbox1 = QHBoxLayout()
hbox1.addLayout(vbox1)
hbox1.addLayout(hbox2)
self.setLayout(hbox1)
self.setGeometry(100, 100, 800, 600)
self.setWindowTitle('Pictures selection for stereo calibration')
self.timer = QTimer()
self.timer.timeout.connect(self.update)
self.timer.start(10)
def update(self):
if self.upd == 1:
frame1 = cv2.imread(self.imagesRight[self.num])
frame2 = cv2.imread(self.imagesLeft[self.num])
chessboardSize=(8,6)
self.imgR = undistort(frame1)
self.imgL = cv2.rotate(frame2, cv2.ROTATE_180)
grayR = cv2.cvtColor(self.imgR, cv2.COLOR_BGR2GRAY)
grayL = cv2.cvtColor(self.imgL, cv2.COLOR_BGR2GRAY)
# Find the chess board corners
retL, cornersL = cv2.findChessboardCorners(grayL, chessboardSize, None)
retR, cornersR = cv2.findChessboardCorners(grayR, chessboardSize, None)
# If found, add object points, image points (after refining them)
if retL and retR == True :
cv2.drawChessboardCorners(self.imgL, chessboardSize, cornersL, retL)
cv2.drawChessboardCorners(self.imgR, chessboardSize, cornersR, retR)
if self.imagesRight[self.num] in self.deleteRight:
opacity = 0.4
self.imgR = cv2.addWeighted(self.overlayDelete, opacity, self.imgR, 1 - opacity, 0)
self.imgL = cv2.addWeighted(self.overlayDelete, opacity, self.imgL, 1 - opacity, 0)
rgbImage1 = cv2.cvtColor(self.imgR, cv2.COLOR_BGR2RGB)
h1, w1, ch1 = rgbImage1.shape
bytesPerLine1 = ch1 * w1
qImg1 = QImage(rgbImage1.data, w1, h1, bytesPerLine1, QImage.Format_RGB888)
pixmap1 = QPixmap.fromImage(qImg1)
self.label1.setPixmap(pixmap1.scaled(360, 270))
rgbImage2 = cv2.cvtColor(self.imgL, cv2.COLOR_BGR2RGB)
h2, w2, ch2 = rgbImage2.shape
bytesPerLine2 = ch2 * w2
qImg2 = QImage(rgbImage2.data, w2, h2, bytesPerLine2, QImage.Format_RGB888)
pixmap2 = QPixmap.fromImage(qImg2)
self.label2.setPixmap(pixmap2.scaled(360, 270))
self.upd=0
def previous(self):
if self.num != 0:
self.num-=1
self.upd=1
def next(self):
if self.num != len(self.imagesRight)-1:
self.num+=1
self.upd=1
def delete(self):
if self.imagesRight[self.num] not in self.deleteRight:
self.deleteRight.append(self.imagesRight[self.num])
self.deleteLeft.append(self.imagesLeft[self.num])
self.upd=1
def undo(self):
if self.imagesRight[self.num] in self.deleteRight:
self.deleteRight.remove(self.imagesRight[self.num])
self.deleteLeft.remove(self.imagesLeft[self.num])
self.upd=1
def validate(self):
for right,left in zip(self.deleteRight,self.deleteLeft):
delete_pic(right)
delete_pic(left)
self.close()
if __name__ == '__main__':
app = QApplication(sys.argv)
win = StereoWindow()
win.show()
sys.exit(app.exec_())