Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import wx
- import cv2
- import numpy as np
- class VideoFrame(wx.Frame):
- def __init__(self, parent, id):
- wx.Frame.__init__(self, parent, id, 'CLIPER 1.0', size=(1640,360))
- self.CreateStatusBar()
- menubar=wx.MenuBar()
- filem=wx.Menu()
- effects = wx.Menu()
- help = wx.Menu()
- info = wx.Menu()
- menubar.Append(filem, '&Plik')
- menubar.Append(effects, '&Efekty')
- menubar.Append(info, 'Twórcy')
- menubar.Append(help, 'Pomoc')
- filem.Append(wx.NewId(), "Nowe Okno", "This is a new window")
- filem.Append(wx.NewId(), '&Otwórz', 'Otwórz plik')
- filem.Append(wx.NewId(), 'Zapisz', 'Zapisz film')
- filem.AppendSeparator()
- menuExit = filem.Append(wx.ID_EXIT, '&Zamknij', 'Zamknij aplikacje')
- self.Bind(wx.EVT_CLOSE, self.OnClose, menuExit)
- effects.Append(wx.ID_ANY, '&Czarno-biały', 'Filtr czarno-biały')
- effects.Append(wx.ID_ANY, '&Sepia', 'Filtr sepii')
- effects.Append(wx.ID_ANY, '&Erozja', 'Efekt erozji')
- effects.Append(wx.ID_ANY, '&Rozmycie', 'Efekt rozmycia')
- info.Append(wx.ID_ABOUT, 'Autor', 'Informacje o autorze aplikacji')
- self.SetMenuBar(menubar)
- def OnClose(self, event):
- if event.VideoFrame():
- if wx.MessageBox("The file has not been saved... continue closing?",
- "Please confirm",
- wx.ICON_QUESTION | wx.YES_NO) != wx.YES:
- event.VideoFrame()
- return
- self.Quit()
- self.Destroy() # you may also do: event.Skip()
- # since the default event handler does call Destroy(), too
- class ShowCapture(wx.Panel):
- def __init__(self, parent, capture, fps=23.97, size=(1040,1060)):
- wx.Panel.__init__(self, parent)
- self.capture = capture
- ret, frame = self.capture.read()
- height, width = frame.shape[:2]
- parent.SetSize((width, height))
- frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
- self.bmp = wx.BitmapFromBuffer(width, height, frame)
- self.timer = wx.Timer(self)
- self.timer.Start(1000./fps)
- self.Bind(wx.EVT_PAINT, self.OnPaint)
- self.Bind(wx.EVT_TIMER, self.NextFrame)
- def OnPaint(self, evt):
- dc = wx.BufferedPaintDC(self)
- dc.DrawBitmap(self.bmp, 0, 0)
- def NextFrame(self, event):
- ret, frame = self.capture.read()
- if ret:
- frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
- tryb = 0 # 0 - kolor; 1 - czarno białe; 2 - sepia 3 - erozja 4 - rozmycie
- new_frame = np.zeros((200, 200))
- key = cv2.waitKey(0)
- if key == ord('q'):
- self.Quit()
- elif key == ord('x'): # koloroweqq
- tryb = 0
- elif key == ord('c'): # czarno białe
- tryb = 1
- elif key == ord('v'): # sepia
- tryb = 2
- elif key == ord('b'): # erozja
- tryb = 3
- elif key == ord('n'): # rozmycie gaussowskie
- tryb = 4
- if tryb == 0: # kolorowe
- new_frame = frame
- elif tryb == 1: # czarno białe
- new_frame = cv2.cvtColor(cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY), cv2.COLOR_GRAY2BGR)
- elif tryb == 2: # sepia
- kernel = np.asarray([0.272, 0.534, 0.131, 0.349, 0.686, 0.168, 0.393, 0.769, 0.189]).reshape(3, 3)
- new_frame = cv2.transform(frame, kernel)
- elif tryb == 3: #erozja
- kernel = np.ones((5,5), np.uint8)
- new_frame = cv2.erode(frame, kernel, iterations=1)
- elif tryb == 4: #rozmycie
- new_frame = cv2.GaussianBlur(frame,(5,5),0)
- self.bmp.CopyFromBuffer(frame)
- self.Refresh()
- capture = cv2.VideoCapture("sample1.mp4")
- width = capture.get(cv2.CAP_PROP_FRAME_WIDTH)
- height = capture.get(cv2.CAP_PROP_FRAME_HEIGHT)
- capture.set(cv2.CAP_PROP_FRAME_WIDTH, width)
- capture.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
- app = wx.App()
- frame = wx.Frame(None)
- frame = VideoFrame(parent=None, id=-1)
- cap = ShowCapture(frame, capture)
- frame.Show()
- app.MainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement