def openBMP(self): # 打开图像,并复制一份,所有图像处理操作在这个复制图像上进行R self.image = wx.Image(self.filename, wx.BITMAP_TYPE_BMP) self.bitmap = imglib.readImg(self.filename) self.tmpImg = './tmp.bmp' self.bitmap.save_to(self.tmpImg) self.sb1 = wx.StaticBitmap(self.panel, pos = ((self.panel.Size[0] - self.image.Width)/2, (self.panel.Size[1]-self.image.Height)/2), id = -1, bitmap = wx.BitmapFromImage(self.image)) self.sb1.Bind(wx.EVT_MOTION, self.getImageGray) self.sb1.Bind(wx.EVT_LEFT_DOWN, self.setDownPoint) self.sb1.Bind(wx.EVT_LEFT_UP, self.setUpPoint)
def OnSearchSimilarImg(self, evt): pathDlg = wx.DirDialog(self, "Select a dir", os.getcwd()) if pathDlg.ShowModal() == wx.ID_OK: self.path = pathDlg.GetPath() filenames = os.listdir(self.path) filenames = filter(lambda filename: filename[-4:] == ".bmp", filenames) filenames = [self.path + "/" + filename for filename in filenames] hists = [imglib.readImg(filename).hist() for filename in filenames] bitmaphist = self.bitmap.hist() diff = [np.sum((bitmaphist - hist) ** 2, axis=0) for hist in hists] sortedImg = np.argsort(diff, axis=0) label = u"共发现{filenum}个.bmp格式文件, 按直方图相似度排序为:".format(filenum=len(filenames)) for item, value in enumerate(sortedImg): label += u"\n" + str(item + 1) + u"." + filenames[value].split("/")[-1] if item > 9: break self.similarImg.SetLabel(label) pathDlg.Destroy() dlg = self.createImageDialog() if dlg.ShowModal() == wx.ID_OK: print "OK"
def OnCancel(self, evt): self.EnableToolbarBtns() self.image = wx.Image(self.filename, wx.BITMAP_TYPE_BMP) self.bitmap = imglib.readImg(self.filename) self.sb1.SetBitmap(wx.BitmapFromImage(self.image)) self.sb1.Refresh()