Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def prevImage(self, event):
"""
Checks the previous Image and enables user to move the annotations.
"""
MainFrame.saveEachImage(self)
# Checks if zoom/pan button is ON
MainFrame.updateZoomPan(self)
self.statusbar.SetStatusText('Working on folder: {}'.format(os.path.split(str(self.dir))[-1]))
self.next.Enable(True)
self.iter = self.iter - 1
# Checks for the first image and disables the Previous button
if self.iter == 0:
self.prev.Enable(False)
if self.iter >= 0:
self.updatedCoords = []
# Reading Image
self.img = os.path.join(self.project_path,self.index[self.iter])
def nextImage(self, event):
"""
Reads the next image and enables the user to move the annotations
"""
# Checks for the last image and disables the Next button
if len(self.index) - self.iter == 1:
self.next.Enable(False)
return
self.prev.Enable(True)
# Checks if zoom/pan button is ON
MainFrame.updateZoomPan(self)
MainFrame.saveEachImage(self)
self.statusbar.SetStatusText('Working on folder: {}'.format(os.path.split(str(self.dir))[-1]))
self.iter = self.iter + 1
if len(self.index) > self.iter:
self.updatedCoords = []
self.img = os.path.join(self.project_path,self.index[self.iter])
img_name = Path(self.img).name
# Plotting
self.figure.delaxes(self.figure.axes[1]) # Removes the axes corresponding to the colorbar
self.figure,self.axes,self.canvas,self.toolbar = self.image_panel.drawplot(self.img,img_name,self.iter,self.index,self.threshold,self.bodyparts,self.colormap,self.preview,keep_view=self.view_locked)
im = io.imread(self.img)
self.axes.callbacks.connect('xlim_changed', self.onZoom)
def nextImage(self, event):
"""
Reads the next image and enables the user to move the annotations
"""
# Checks for the last image and disables the Next button
if len(self.index) - self.iter == 1:
self.next.Enable(False)
return
self.prev.Enable(True)
# Checks if zoom/pan button is ON
MainFrame.updateZoomPan(self)
MainFrame.saveEachImage(self)
self.statusbar.SetStatusText('Working on folder: {}'.format(os.path.split(str(self.dir))[-1]))
self.iter = self.iter + 1
if len(self.index) > self.iter:
self.updatedCoords = []
self.img = os.path.join(self.project_path,self.index[self.iter])
img_name = Path(self.img).name
# Plotting
self.figure.delaxes(self.figure.axes[1]) # Removes the axes corresponding to the colorbar
self.figure,self.axes,self.canvas,self.toolbar = self.image_panel.drawplot(self.img,img_name,self.iter,self.index,self.threshold,self.bodyparts,self.colormap,self.preview,keep_view=self.view_locked)
im = io.imread(self.img)
self.axes.callbacks.connect('xlim_changed', self.onZoom)
self.axes.callbacks.connect('ylim_changed', self.onZoom)
if np.max(im) == 0:
if self.move2corner==True:
ny,nx=np.shape(im)[0],np.shape(im)[1]
if self.points[0]>nx or self.points[0]<0:
self.points[0]=self.center[0]
if self.points[1]>ny or self.points[1]<0:
self.points[1]= self.center[1]
if not ('CollectedData_' in self.fileName) and self.likelihood < self.threshold:
circle = [patches.Circle((self.points[0], self.points[1]), radius=self.markerSize, facecolor = 'None', edgecolor = color)]
else:
circle = [patches.Circle((self.points[0], self.points[1]), radius=self.markerSize, fc = color, alpha=self.alpha)]
self.axes.add_patch(circle[0])
self.dr = auxfun_drag.DraggablePoint(circle[0],bp,self.likelihood)
self.dr.connect()
self.dr.coords = MainFrame.getLabels(self,self.iter)[bpindex]
self.drs.append(self.dr)
self.updatedCoords.append(self.dr.coords)
self.figure.canvas.draw()
# Checks for the first image and disables the Previous button
if self.iter == 0:
self.prev.Enable(False)
if self.iter >= 0:
self.updatedCoords = []
# Reading Image
self.img = os.path.join(self.project_path,self.index[self.iter])
img_name = Path(self.img).name
# Plotting
self.figure.delaxes(self.figure.axes[1]) # Removes the axes corresponding to the colorbar
self.figure,self.axes,self.canvas,self.toolbar = self.image_panel.drawplot(self.img,img_name,self.iter,self.index,self.threshold,self.bodyparts,self.colormap,self.preview,keep_view=self.view_locked)
self.axes.callbacks.connect('xlim_changed', self.onZoom)
self.axes.callbacks.connect('ylim_changed', self.onZoom)
MainFrame.plot(self,self.img)
else:
self.prev.Enable(False)
MainFrame.saveEachImage(self)
def saveDataSet(self, event):
MainFrame.saveEachImage(self)
# Checks if zoom/pan button is ON
MainFrame.updateZoomPan(self)
self.statusbar.SetStatusText("File saved")
self.Dataframe = MainFrame.check_labels(self)
# Overwrite machine label file
self.Dataframe.to_hdf(self.dataname, key='df_with_missing', mode='w')
self.Dataframe.columns.set_levels([self.scorer.replace(self.scorer,self.humanscorer)],level=0,inplace=True)
self.Dataframe = self.Dataframe.drop('likelihood',axis=1,level=2)
if Path(self.dir,'CollectedData_'+self.humanscorer+'.h5').is_file():
print("A training dataset file is already found for this video. The refined machine labels are merged to this data!")
DataU1 = pd.read_hdf(os.path.join(self.dir,'CollectedData_'+self.humanscorer+'.h5'), 'df_with_missing')
# combine datasets Original Col. + corrected machinefiles:
DataCombined = pd.concat([self.Dataframe,DataU1])
# Now drop redundant ones keeping the first one [this will make sure that the refined machine file gets preference]
DataCombined = DataCombined[~DataCombined.index.duplicated(keep='first')]
'''
if len(self.droppedframes)>0: #i.e. frames were dropped/corrupt. also remove them from original file (if they exist!)
for fn in self.droppedframes:
"""
If ok is selected then the image is updated with the thresholded value of the likelihood
"""
textBox = wx.TextEntryDialog(self, "Select the likelihood threshold",caption = "Enter the threshold",value="0.1")
textBox.ShowModal()
self.threshold = float(textBox.GetValue())
textBox.Destroy()
self.img = os.path.join(self.project_path,self.index[self.iter])
img_name = Path(self.img).name
self.axes.clear()
self.preview = False
self.figure.delaxes(self.figure.axes[1]) # Removes the axes corresponding to the colorbar
self.figure,self.axes,self.canvas,self.toolbar = self.image_panel.drawplot(self.img,img_name,self.iter,self.index,self.threshold,self.bodyparts,self.colormap,self.preview)
self.axes.callbacks.connect('xlim_changed', self.onZoom)
self.axes.callbacks.connect('ylim_changed', self.onZoom)
MainFrame.plot(self,self.img)
MainFrame.saveEachImage(self)
else:
self.figure.delaxes(self.figure.axes[1]) # Removes the axes corresponding to the colorbar
self.figure,self.axes,self.canvas,self.toolbar = self.image_panel.drawplot(self.img,img_name,self.iter,self.index,self.threshold,self.bodyparts,self.colormap,self.preview)
self.axes.callbacks.connect('xlim_changed', self.onZoom)
self.axes.callbacks.connect('ylim_changed', self.onZoom)
MainFrame.plot(self,self.img)
MainFrame.saveEachImage(self)
else:
msg = wx.MessageBox('No Machinelabels file found! Want to retry?', 'Error!', wx.YES_NO | wx.ICON_WARNING)
if msg == 2:
self.load.Enable(True)
self.next.Enable(False)
self.save.Enable(False)
self.next.Enable(False)
self.prev.Enable(False)
self.slider.Enable(False)
self.checkBox.Enable(False)
nextFilemsg = wx.MessageBox('File saved. Do you want to refine another file?', 'Repeat?', wx.YES_NO | wx.ICON_INFORMATION)
if nextFilemsg == 2:
self.file = 1
self.axes.clear()
self.figure.delaxes(self.figure.axes[1])
self.choiceBox.Clear(True)
MainFrame.updateZoomPan(self)
self.load.Enable(True)
# self.slider.Enable(False)
# self.checkBox.Enable(False)
MainFrame.browseDir(self, event)
else:
self.Dataframe.sort_index(inplace=True)
self.Dataframe.to_hdf(os.path.join(self.dir,'CollectedData_'+ self.humanscorer+'.h5'), key='df_with_missing', mode='w')
self.Dataframe.to_csv(os.path.join(self.dir,'CollectedData_'+ self.humanscorer +'.csv'))
self.next.Enable(False)
self.prev.Enable(False)
self.slider.Enable(False)
self.checkBox.Enable(False)
nextFilemsg = wx.MessageBox('File saved. Do you want to refine another file?', 'Repeat?', wx.YES_NO | wx.ICON_INFORMATION)
if nextFilemsg == 2:
self.file = 1
self.axes.clear()
self.figure.delaxes(self.figure.axes[1])
self.choiceBox.Clear(True)
MainFrame.updateZoomPan(self)
self.load.Enable(True)
# self.slider.Enable(False)
# self.checkBox.Enable(False)
MainFrame.browseDir(self, event)