Advertisement
Guest User

błędy

a guest
Jul 17th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.35 KB | None | 0 0
  1. import wx
  2. import cv2
  3. import numpy as np
  4.  
  5.  
  6. class VideoFrame(wx.Frame):
  7.        
  8.     def __init__(self, parent, id):
  9.         wx.Frame.__init__(self, parent, id, 'CLIPER 1.0', size=(1640,360))
  10.         self.CreateStatusBar()
  11.         menubar=wx.MenuBar()
  12.         filem=wx.Menu()
  13.         effects = wx.Menu()
  14.         help = wx.Menu()
  15.         info = wx.Menu()
  16.        
  17.         menubar.Append(filem, '&Plik')
  18.         menubar.Append(effects, '&Efekty')
  19.         menubar.Append(info, 'Twórcy')
  20.         menubar.Append(help, 'Pomoc')
  21.        
  22.         filem.Append(wx.NewId(), "Nowe Okno", "This is a new window")
  23.         filem.Append(wx.NewId(), '&Otwórz', 'Otwórz plik')
  24.         filem.Append(wx.NewId(), 'Zapisz', 'Zapisz film')
  25.         filem.AppendSeparator()
  26.         menuExit = filem.Append(wx.ID_EXIT, '&Zamknij', 'Zamknij aplikacje')
  27.         self.Bind(wx.EVT_CLOSE, self.OnClose, menuExit)
  28.        
  29.         effects.Append(wx.ID_ANY, '&Czarno-biały', 'Filtr czarno-biały')
  30.         effects.Append(wx.ID_ANY, '&Sepia', 'Filtr sepii')
  31.         effects.Append(wx.ID_ANY, '&Erozja', 'Efekt erozji')
  32.         effects.Append(wx.ID_ANY, '&Rozmycie', 'Efekt rozmycia')
  33.         info.Append(wx.ID_ABOUT, 'Autor', 'Informacje o autorze aplikacji')
  34.        
  35.         self.SetMenuBar(menubar)
  36.        
  37.     def OnClose(self, event):
  38.  
  39.         if event.VideoFrame():
  40.  
  41.           if wx.MessageBox("The file has not been saved... continue closing?",
  42.                          "Please confirm",
  43.                          wx.ICON_QUESTION | wx.YES_NO) != wx.YES:
  44.  
  45.               event.VideoFrame()
  46.               return
  47.         self.Quit()
  48.         self.Destroy()  # you may also do:  event.Skip()
  49.                     # since the default event handler does call Destroy(), too
  50.        
  51.  
  52. class ShowCapture(wx.Panel):
  53.     def __init__(self, parent, capture, fps=23.97, size=(1040,1060)):
  54.         wx.Panel.__init__(self, parent)        
  55.         self.capture = capture
  56.         ret, frame = self.capture.read()
  57.  
  58.         height, width = frame.shape[:2]
  59.         parent.SetSize((width, height))
  60.         frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
  61.  
  62.         self.bmp = wx.BitmapFromBuffer(width, height, frame)
  63.         self.timer = wx.Timer(self)
  64.         self.timer.Start(1000./fps)
  65.  
  66.         self.Bind(wx.EVT_PAINT, self.OnPaint)
  67.         self.Bind(wx.EVT_TIMER, self.NextFrame)
  68.  
  69.     def OnPaint(self, evt):
  70.         dc = wx.BufferedPaintDC(self)
  71.         dc.DrawBitmap(self.bmp, 0, 0)
  72.  
  73.     def NextFrame(self, event):
  74.         ret, frame = self.capture.read()
  75.         if ret:
  76.             frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
  77.             tryb = 0 # 0 - kolor; 1 - czarno białe; 2 - sepia 3 - erozja 4 - rozmycie
  78.             new_frame = np.zeros((200, 200))
  79.  
  80.             key = cv2.waitKey(0)
  81.  
  82.             if key == ord('q'):
  83.                 self.Quit()
  84.             elif key == ord('x'): # koloroweqq
  85.                 tryb = 0
  86.             elif key == ord('c'): # czarno białe        
  87.                 tryb = 1
  88.             elif key == ord('v'): # sepia
  89.                 tryb = 2
  90.             elif key == ord('b'): # erozja
  91.                 tryb = 3
  92.             elif key == ord('n'): # rozmycie gaussowskie    
  93.                 tryb = 4
  94.            
  95.             if tryb == 0: # kolorowe
  96.                 new_frame = frame
  97.             elif tryb == 1: # czarno białe
  98.                 new_frame = cv2.cvtColor(cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY), cv2.COLOR_GRAY2BGR)
  99.             elif tryb == 2: # sepia
  100.                 kernel = np.asarray([0.272, 0.534, 0.131, 0.349, 0.686, 0.168, 0.393, 0.769, 0.189]).reshape(3, 3)
  101.                 new_frame = cv2.transform(frame, kernel)
  102.             elif tryb == 3: #erozja
  103.                 kernel = np.ones((5,5), np.uint8)
  104.                 new_frame = cv2.erode(frame, kernel, iterations=1)
  105.             elif tryb == 4: #rozmycie
  106.                 new_frame = cv2.GaussianBlur(frame,(5,5),0)
  107.            
  108.             self.bmp.CopyFromBuffer(frame)
  109.             self.Refresh()
  110.  
  111. capture = cv2.VideoCapture("sample1.mp4")
  112. width = capture.get(cv2.CAP_PROP_FRAME_WIDTH)
  113. height = capture.get(cv2.CAP_PROP_FRAME_HEIGHT)
  114. capture.set(cv2.CAP_PROP_FRAME_WIDTH, width)
  115. capture.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
  116.  
  117.  
  118. app = wx.App()
  119. frame = wx.Frame(None)
  120. frame = VideoFrame(parent=None, id=-1)
  121. cap = ShowCapture(frame, capture)
  122. frame.Show()
  123. app.MainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement