-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselect_fish.py
126 lines (97 loc) · 3.77 KB
/
select_fish.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
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 FishWindow(QWidget):
def __init__(self):
super().__init__()
self.initUI()
self.num = 0
self.imagesFish = sorted(glob.glob('calibration/img_calib/img_fisheye_indi/*.jpg'))
self.deleteFish=[]
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 fisheye 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.imagesFish[self.num])
chessboardSize=(8,6)
self.imgR = undistort(frame1)
grayR = cv2.cvtColor(self.imgR, cv2.COLOR_BGR2GRAY)
# Find the chess board corners
retR, cornersR = cv2.findChessboardCorners(grayR, chessboardSize, None)
# If found, add object points, image points (after refining them)
if retR == True :
cv2.drawChessboardCorners(self.imgR, chessboardSize, cornersR, retR)
if self.imagesFish[self.num] in self.deleteFish:
opacity = 0.4
self.imgR = cv2.addWeighted(self.overlayDelete, opacity, self.imgR, 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))
self.upd = 0
def previous(self):
if self.num != 0:
self.num-=1
self.upd = 1
def next(self):
if self.num != len(self.imagesFish)-1:
self.num+=1
self.upd = 1
def delete(self):
if self.imagesFish[self.num] not in self.deleteFish:
self.deleteFish.append(self.imagesFish[self.num])
self.upd=1
def undo(self):
if self.imagesFish[self.num] in self.deleteFish:
self.deleteFish.remove(self.imagesFish[self.num])
self.upd=1
def validate(self):
for right in self.deleteFish:
delete_pic(right)
self.close()
if __name__ == '__main__':
app = QApplication(sys.argv)
win = FishWindow()
win.show()
sys.exit(app.exec_())