|
@@ -1,3 +1,5 @@
|
|
|
+import os
|
|
|
+import subprocess
|
|
|
|
|
|
from PyQt5.QtWidgets import (QWidget,QVBoxLayout,QTabWidget,QSplitter, QFileDialog,QMessageBox,QComboBox,
|
|
|
QLineEdit,QTextEdit,QCheckBox,QLabel,QFrame,QPushButton,QMenu,QAction)
|
|
@@ -10,12 +12,13 @@ import GrpcClient as rpc
|
|
|
import vtk
|
|
|
import cv2
|
|
|
import time
|
|
|
+import google.protobuf.text_format as tf
|
|
|
from vtkmodules.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
|
|
|
#from vtk.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
|
|
|
|
|
|
import threading
|
|
|
class ControlFrame(QFrame):
|
|
|
- cameraMap={"相机1":1,"相机2":2,"相机3":3,"相机4":4}
|
|
|
+ cameraMap={"相机1":0,"相机2":1,"相机3":2,"相机4":3}
|
|
|
def __init__(self):
|
|
|
QFrame.__init__(self)
|
|
|
self.setGeometry(0, 0, 500, 500)
|
|
@@ -96,37 +99,33 @@ class ControlFrame(QFrame):
|
|
|
self.btnSaveWheelSampleCloud.setGeometry(150, 170, 100, 30)
|
|
|
self.btnSaveWheelSampleCloud.setText("保存轮胎样本")
|
|
|
|
|
|
+ self.ParameterEdit = QTextEdit(self)
|
|
|
+ self.ParameterEdit.setText("")
|
|
|
+ self.ParameterEdit.setGeometry(20, 300, 130, 150)
|
|
|
+
|
|
|
self.MatrixEdit = QTextEdit(self)
|
|
|
+ self.MatrixEdit.setAlignment(Qt.AlignTop)
|
|
|
self.MatrixEdit.setText("输入4x4变换矩阵")
|
|
|
self.MatrixEdit.setGeometry(20, 205, 500, 90)
|
|
|
- #self.MatrixEdit.setLineWrapMode()
|
|
|
- self.MatrixEdit.setAlignment(Qt.AlignTop)
|
|
|
- self.btnMatrix = QPushButton(self)
|
|
|
- self.btnMatrix.setGeometry(20, 300, 100, 30)
|
|
|
- self.btnMatrix.setText("转换rpy,xyz")
|
|
|
- self.btnMatrix.clicked.connect(self.matrix2rpy)
|
|
|
-
|
|
|
- self.ParameterEdit = QTextEdit(self)
|
|
|
- self.ParameterEdit.setText("")
|
|
|
- self.ParameterEdit.setGeometry(20, 340, 130, 150)
|
|
|
+ self.MatrixEdit.textChanged.connect(self.matrix2rpy)
|
|
|
|
|
|
self.CameraListEdit=QComboBox(self)
|
|
|
self.CameraListEdit.addItems(self.cameraMap.keys())
|
|
|
- self.CameraListEdit.setGeometry(155, 340, 100, 30)
|
|
|
+ self.CameraListEdit.setGeometry(155, 300, 100, 30)
|
|
|
|
|
|
|
|
|
self.btnChange = QPushButton(self)
|
|
|
- self.btnChange.setGeometry(155, 390, 100, 40)
|
|
|
+ self.btnChange.setGeometry(155, 350, 100, 40)
|
|
|
self.btnChange.setText("修改参数")
|
|
|
self.btnChange.clicked.connect(self.ChangeCameraParameter)
|
|
|
|
|
|
self.btnSave = QPushButton(self)
|
|
|
- self.btnSave.setGeometry(155, 450, 100, 40)
|
|
|
+ self.btnSave.setGeometry(155, 410, 100, 40)
|
|
|
self.btnSave.setText("写入参数")
|
|
|
self.btnSave.clicked.connect(self.SaveCameraParameter)
|
|
|
|
|
|
self.ErrorInfo = QLabel(self)
|
|
|
- self.ErrorInfo.setGeometry(20, 495, 250, 400)
|
|
|
+ self.ErrorInfo.setGeometry(20, 455, 250, 400)
|
|
|
self.ErrorInfo.setWordWrap(True)
|
|
|
self.ErrorInfo.setAlignment(Qt.AlignTop)
|
|
|
|
|
@@ -236,17 +235,48 @@ class ControlFrame(QFrame):
|
|
|
z = 0
|
|
|
return np.array([x, y, z])
|
|
|
def SaveCameraParameter(self):
|
|
|
+ self.btnSave.setEnabled(False)
|
|
|
camera=self.CameraListEdit.currentText()
|
|
|
id=self.cameraMap[camera]
|
|
|
text=self.ParameterEdit.toPlainText()
|
|
|
-
|
|
|
- print(" 保存相机%d参数:%s"%(id,text))
|
|
|
+ transform=pb.CoordinateTransformation3D()
|
|
|
+ try:
|
|
|
+ tf.Parse(text, transform)
|
|
|
+ except:
|
|
|
+ QMessageBox.information(self, '格式错误',text,QMessageBox.Ok,QMessageBox.Ok)
|
|
|
+ self.btnSave.setEnabled(True)
|
|
|
+ print(" 保存相机%d参数:%s"%(id,transform))
|
|
|
+ client=rpc.GrpcStream()
|
|
|
+ ip=self.IPEdit.text()
|
|
|
+ port=int(self.PortEdit.text())
|
|
|
+ try:
|
|
|
+ ret=client.SaveCameraParameter(ip,port,id,transform)
|
|
|
+ QMessageBox.information(self, 'Info',ret.info,QMessageBox.Ok,QMessageBox.Ok)
|
|
|
+ except Exception as e:
|
|
|
+ QMessageBox.information(self, 'Info',str(e),QMessageBox.Ok,QMessageBox.Ok)
|
|
|
+ self.btnSave.setEnabled(True)
|
|
|
def ChangeCameraParameter(self):
|
|
|
+ self.btnChange.setEnabled(False)
|
|
|
camera=self.CameraListEdit.currentText()
|
|
|
id=self.cameraMap[camera]
|
|
|
text=self.ParameterEdit.toPlainText()
|
|
|
-
|
|
|
- print(" 修改相机%d参数:%s"%(id,text))
|
|
|
+ transform=pb.CoordinateTransformation3D()
|
|
|
+ try:
|
|
|
+ tf.Parse(text, transform)
|
|
|
+ except:
|
|
|
+ QMessageBox.information(self, '格式错误',text,QMessageBox.Ok,QMessageBox.Ok)
|
|
|
+ self.btnChange.setEnabled(True)
|
|
|
+ return
|
|
|
+ print(" 修改相机%d参数:%s"%(id,transform))
|
|
|
+ client=rpc.GrpcStream()
|
|
|
+ ip=self.IPEdit.text()
|
|
|
+ port=int(self.PortEdit.text())
|
|
|
+ try:
|
|
|
+ ret=client.ChangeCameraParameter(ip,port,id,transform)
|
|
|
+ QMessageBox.information(self, 'Info',ret.info,QMessageBox.Ok,QMessageBox.Ok)
|
|
|
+ except Exception as e:
|
|
|
+ QMessageBox.information(self, 'Info',str(e),QMessageBox.Ok,QMessageBox.Ok)
|
|
|
+ self.btnChange.setEnabled(True)
|
|
|
def matrix2rpy(self):
|
|
|
text=""
|
|
|
str=self.MatrixEdit.toPlainText()
|
|
@@ -266,8 +296,9 @@ class ControlFrame(QFrame):
|
|
|
count+=1
|
|
|
|
|
|
rpy=self.rotationMatrixToEulerAngles(matrix)
|
|
|
- text="\"roll\" : %.3f,\n\"pitch\": %.3f,\n\"yaw\": %.3f,\n\"x\":%.3f,\n\"y\":%.3f,\n\"z\":%.3f,"%(math.degrees(rpy[0]),math.degrees(rpy[1]),math.degrees(rpy[2]),
|
|
|
+ text="roll : %.3f,\npitch: %.3f,\nyaw: %.3f,\nx:%.3f,\ny:%.3f,\nz:%.3f,"%(math.degrees(rpy[0]),math.degrees(rpy[1]),math.degrees(rpy[2]),
|
|
|
matrix[0,3],matrix[1,3],matrix[2,3])
|
|
|
+
|
|
|
self.ParameterEdit.setText(text)
|
|
|
#QMessageBox.information(self, '旋转变换转rpy-t',text,QMessageBox.Ok,QMessageBox.Ok)
|
|
|
def btnCancelClick(self):
|
|
@@ -427,17 +458,20 @@ class PointCLViwer(QSplitter):
|
|
|
self.addWidget(self.pclViewer)
|
|
|
self.setStretchFactor(0,4)
|
|
|
def save(self):
|
|
|
- fileName2, ok2 = QFileDialog.getSaveFileName(self, "文件保存", "C:/","All Files (*);;Text Files (*.txt)")
|
|
|
- print(fileName2 ,ok2)
|
|
|
+ #fileName2, ok2 = QFileDialog.getSaveFileName(self, "文件保存", "C:/","All Files (*);;Text Files (*.txt)")
|
|
|
+ #print(fileName2 ,ok2)
|
|
|
+ fileName2="./cloud/%d.txt"%(self.id)
|
|
|
with open(fileName2,"w+") as f:
|
|
|
for point in self.pointCloud:
|
|
|
prob=point[3]
|
|
|
f.write("%f %f %f %d %d %d\n"%(point[0],point[1],point[2],int(255*prob),int(255-prob*255),255-int(prob*255)))
|
|
|
|
|
|
print("Save Cloud to %s"%(fileName2))
|
|
|
+ subprocess.Popen(["cloudcompare.CloudCompare",fileName2])
|
|
|
+ #os.system("cloudcompare.CloudCompare %s"%(fileName2))
|
|
|
def saveWheel(self):
|
|
|
- fileName2, ok2 = QFileDialog.getSaveFileName(self, "文件保存", "C:/","All Files (*);;Text Files (*.txt)")
|
|
|
- print(fileName2 ,ok2)
|
|
|
+ #fileName2, ok2 = QFileDialog.getSaveFileName(self, "文件保存", "C:/","All Files (*);;Text Files (*.txt)")
|
|
|
+ fileName2="./cloud/%d-wheel.txt"%(self.id)
|
|
|
with open(fileName2,"w+") as f:
|
|
|
for point in self.pointCloud:
|
|
|
prob=point[3]
|