Skip to content

Instantly share code, notes, and snippets.

@Superbil
Last active December 18, 2015 15:49
Show Gist options
  • Save Superbil/5806704 to your computer and use it in GitHub Desktop.
Save Superbil/5806704 to your computer and use it in GitHub Desktop.
# -*- encoding: utf-8 -*-
import wx
import os.path
from wx.lib.dialogs import openFileDialog
from SimpleCV import Image, Color, Display
# Make a function that does a half and half image.
def halfsies(left, right):
result = left
# crop the right image to be just the right side.
crop = right.crop(right.width/2.0,0,right.width/2.0,right.height)
# now paste the crop on the left image.
result = result.blit(crop,(left.width/2,0))
# return the results.
return result
class Example(wx.Frame):
file_path = ""
def __init__(self, *args, **kw):
super(Example, self).__init__(*args, **kw)
self.InitUI()
def InitUI(self):
pnl = wx.Panel(self)
self.col = wx.Colour(0, 0, 0)
rtb = wx.Button(pnl, label='read', pos=(20, 10),size=(150,30))
gtb = wx.Button(pnl, label='binarize', pos=(20, 50),size=(150,30))
rtb.Bind(wx.EVT_BUTTON, self.OnRead)
gtb.Bind(wx.EVT_BUTTON, self.OnClick)
self.SetSize((350, 200))
self.SetTitle('Toggle buttons')
self.Centre()
self.Show(True)
def OnRead(self, e):
dialog = openFileDialog(
title='Open Image...',
style=wx.OPEN)
self.file_path = unicode(dialog.paths[0])
if __debug__:
print "isFile:%s, path:%s" % (os.path.isfile(self.file_path), self.file_path)
def OnClick(self, e):
img = Image(self.file_path)
if img.width == 0 or img.height == 0:
if __debug__:
print "error on open image:%s" % (self.file_path)
return
output = img.binarize(90).invert()
result = halfsies(img,output)
result.save('juniperbinary.png')
# Show
frame = ShowFrame(None, -1, 'Result')
frame.Show(True)
class ShowFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size = (300,300))
self.bitmap = wx.Bitmap('juniperbinary.png')
wx.EVT_PAINT(self, self.OnPaint)
self.Centre()
def OnPaint(self, event):
dc = wx.PaintDC(self)
dc.DrawBitmap(self.bitmap,0,0)
def main():
ex = wx.App()
Example(None)
ex.MainLoop()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment