Skip to content

Commit

Permalink
actually fix the baseline
Browse files Browse the repository at this point in the history
  • Loading branch information
mvgorcum committed Sep 27, 2020
1 parent 97afe2c commit 142c531
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 10 deletions.
60 changes: 57 additions & 3 deletions Mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,37 @@
<x>0</x>
<y>0</y>
<width>1280</width>
<height>720</height>
<height>721</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<height>200</height>
<width>1280</width>
<height>721</height>
</size>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>1280</width>
<height>668</height>
</size>
</property>
<widget class="QWidget" name="gridLayoutWidget">
<property name="geometry">
<rect>
Expand All @@ -30,14 +48,26 @@
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<item row="0" column="2" rowspan="3">
<widget class="PlotWidget" name="PlotWidget" native="true">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>561</width>
<height>659</height>
</size>
</property>
</widget>
</item>
<item row="0" column="0">
Expand All @@ -48,6 +78,12 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>134</width>
<height>34</height>
</size>
</property>
<property name="text">
<string>Start Measurement</string>
</property>
Expand All @@ -64,10 +100,28 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>562</width>
<height>659</height>
</size>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="CameraToggleButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>134</width>
<height>34</height>
</size>
</property>
<property name="text">
<string>Live Camera</string>
</property>
Expand Down
16 changes: 9 additions & 7 deletions QT_sessile_drop_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def getnextframe(self):
else:
self.is_running=False
self.stop()
return -1
return -1,-1

def getframesize(self):
return self.cap.get(cv2.CAP_PROP_FRAME_WIDTH),self.cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
Expand Down Expand Up @@ -116,7 +116,7 @@ def getnextframe(self):

return self.framebuffer.pop(0),self.framecaptime.pop(0)
else:
return -1
return -1,-1

def getframesize(self):
if not 'self.cap' in locals():
Expand Down 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(parent=self.VideoWidget)
self.VideoItem = pg.ImageView(view=pg.PlotItem(),parent=self.VideoWidget)
self.LeftEdgeItem=pg.PlotCurveItem(pen='#ff7f0e')
self.RightEdgeItem=pg.PlotCurveItem(pen='#1f77b4')
self.VideoItem.addItem(self.LeftEdgeItem)
Expand Down Expand Up @@ -246,18 +246,20 @@ def RunAnalysis(self):
org_frame,framecaptime = self.FrameSource.getnextframe()
if not np.all(org_frame==-1):
#get crop and save coordinate transformation
self.updateVideo.emit(cv2.cvtColor(org_frame, cv2.COLOR_BGR2RGB))
cropcoords=self.CropRoi.getArraySlice(org_frame, self.VideoItem.getImageItem(), returnSlice=False)
verticalCropOffset=0.5+cropcoords[0][0][0]
horizontalCropOffset=0.5+cropcoords[0][1][0]
cropped=org_frame[cropcoords[0][0][0]:cropcoords[0][0][1],cropcoords[0][1][0]:cropcoords[0][1][1],:]

#get baseline positions and extrapolate to the edge of the crop
baselineobj=self.BaseLine.getSceneHandlePositions()
baseinput=[[baselineobj[0][1].x()-horizontalCropOffset,baselineobj[0][1].y()-verticalCropOffset],[baselineobj[1][1].x()-horizontalCropOffset,baselineobj[1][1].y()-verticalCropOffset]]
del baselineobj
_,basearray=self.BaseLine.getArrayRegion(org_frame, self.VideoItem.getImageItem(), returnSlice=False, returnMappedCoords=True)
baseinput=[[basearray[0,0]-horizontalCropOffset,basearray[1,0]-verticalCropOffset],[basearray[0,-1]-horizontalCropOffset,basearray[1,-1]-verticalCropOffset]]
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]]])

gray = cv2.cvtColor(cropped.astype('uint8'), cv2.COLOR_BGR2GRAY)
thresh, _ =cv2.threshold(gray, 0, 255, cv2.THRESH_OTSU)
CroppedEdgeLeft,CroppedEdgeRight=linedge(gray,thresh)
Expand All @@ -266,7 +268,7 @@ def RunAnalysis(self):
contactpointleft, contactpointright, thetal, thetar, dropvolume = analysis(EdgeLeft,EdgeRight,base,baseslope,cropped.shape,k=100,PO=2)
newrow={'thetaleft':thetal, 'thetaright':thetar, 'contactpointleft':contactpointleft,'contactpointright':contactpointright,'volume':dropvolume,'time':framecaptime}
self.MeasurementResult=self.MeasurementResult.append(newrow,ignore_index=True)
self.updateVideo.emit(cv2.cvtColor(org_frame, cv2.COLOR_BGR2RGB))

self.updateLeftEdge.emit(EdgeLeft,np.arange(0,len(EdgeLeft))+verticalCropOffset)
self.updateRightEdge.emit(EdgeRight,np.arange(0,len(EdgeRight))+verticalCropOffset)
self.updatePlotLeft.emit(self.MeasurementResult['time'].to_numpy(),self.MeasurementResult['thetaleft'].to_numpy())
Expand Down

0 comments on commit 142c531

Please sign in to comment.