Skip to content

Commit

Permalink
allow saving a file
Browse files Browse the repository at this point in the history
  • Loading branch information
mvgorcum committed Sep 28, 2020
1 parent 142c531 commit a471dfe
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions QT_sessile_drop_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
uic.loadUi('Mainwindow.ui', self)

self.VideoItem = pg.ImageView(view=pg.PlotItem(),parent=self.VideoWidget)
self.VideoItem = pg.ImageView(parent=self.VideoWidget)
self.LeftEdgeItem=pg.PlotCurveItem(pen='#ff7f0e')
self.RightEdgeItem=pg.PlotCurveItem(pen='#1f77b4')
self.VideoItem.addItem(self.LeftEdgeItem)
Expand All @@ -176,12 +176,13 @@ def __init__(self, *args, **kwargs):
self.updatePlotRight.connect(self.ThetaRightPlot.setData)

self.BaseLine=pg.LineSegmentROI([(15,90),(100,90)],pen='#d62728')
self.CropRoi=pg.RectROI([10,10],[110,110])
self.CropRoi=pg.RectROI([10,10],[110,110],scaleSnap=True)
self.CropRoi.addScaleHandle([0,0],[1,1])
self.VideoItem.addItem(self.BaseLine)
self.VideoItem.addItem(self.CropRoi)

self.actionOpen.triggered.connect(self.openCall)
self.actionSave.triggered.connect(self.SaveResult)
self.StartStopButton.clicked.connect(self.StartStop)
self.CameraToggleButton.clicked.connect(self.CameraToggle)

Expand All @@ -198,7 +199,7 @@ def openCall(self):
FrameWidth,FrameHeight=self.FrameSource.getframesize()
self.CropRoi.setPos([FrameWidth*.1,FrameHeight*.1])
self.CropRoi.setSize([FrameWidth*.8,FrameHeight*.8])
#self.BaseLine.setPos([FrameWidth*.2,FrameHeight*.7])
self.BaseLine.setPos([FrameWidth*.2,FrameHeight*.7])
firstframe,_=self.FrameSource.getnextframe()
self.VideoItem.setImage(cv2.cvtColor(firstframe, cv2.COLOR_BGR2RGB),autoRange=True)

Expand Down Expand Up @@ -258,7 +259,7 @@ def RunAnalysis(self):
del basearray
rightbasepoint=np.argmax([baseinput[0][0],baseinput[1][0]])
baseslope=np.float(baseinput[rightbasepoint][1]-baseinput[1-rightbasepoint][1])/(baseinput[rightbasepoint][0]-baseinput[1-rightbasepoint][0])
base=np.array([[0,baseinput[0][1]-baseslope*baseinput[0][0]],[cropped.shape[1],baseslope*cropped.shape[1]+baseinput[0][1]-baseslope*baseinput[0][0]]])
base=np.array([[0,baseinput[0][1]-baseslope*baseinput[0][0]],[org_frame.shape[1],baseslope*org_frame.shape[1]+baseinput[0][1]-baseslope*baseinput[0][0]]])

gray = cv2.cvtColor(cropped.astype('uint8'), cv2.COLOR_BGR2GRAY)
thresh, _ =cv2.threshold(gray, 0, 255, cv2.THRESH_OTSU)
Expand All @@ -277,8 +278,16 @@ def RunAnalysis(self):
sleep(0.0001)
if (not self.FrameSource.is_running and len(self.FrameSource.framebuffer)<1):
break



def SaveResult(self):
if len(self.MeasurementResult.index)>0:
SaveFileName, _ =QtGui.QFileDialog.getSaveFileName(self,'Save file', '', "Excel Files (*.xlsx);;All Files (*)")
self.MeasurementResult.to_excel(SaveFileName)
else:
errorpopup=QtGui.QMessageBox()
errorpopup.setText('Nothing to save')
errorpopup.setStandardButtons(QtGui.QMessageBox.Ok)
errorpopup.exec_()

def main():
app = QtWidgets.QApplication(sys.argv)
Expand Down

0 comments on commit a471dfe

Please sign in to comment.