Skip to content

Commit

Permalink
Version 1.0a
Browse files Browse the repository at this point in the history
  • Loading branch information
Krol-X committed May 16, 2020
1 parent e1d6da7 commit 52afb5d
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 47 deletions.
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
# Files
*.exe
*.spec
*.bak
*.avi

# Folders
__pycache__
*.bak
build
dist
.idea
Binary file added PyVideo.ico
Binary file not shown.
1 change: 1 addition & 0 deletions __main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ def OnInit(self):
if __name__ == "__main__":
app = MainApp(0)
app.MainLoop()
pass
70 changes: 57 additions & 13 deletions dialog_effects.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
import wx
import wx

ID_OK = 20000
ID_BACK = 20001


#####################################################################
# wx.Dialog Effects
#####################################################################
class Effects(wx.Dialog):
def __init__(self, *args, **kwds):
kwds["style"] = kwds.get("style", 0) | wx.CAPTION
wx.Dialog.__init__(self, *args, **kwds)
self.list_box_1 = wx.ListBox(self, wx.ID_ANY, choices=[r"Blur", r"GaussianBlur", r"medianBlur", r"bilateralFilter"])
self.list_box_1 = wx.ListBox(self, wx.ID_ANY, choices=[r"--", r"Blur", r"GaussianBlur", r"medianBlur", r"bilateralFilter"])
self.spin_1 = wx.SpinCtrl(self, wx.ID_ANY, "0", min=0, max=100)
self.spin_2 = wx.SpinCtrl(self, wx.ID_ANY, "0", min=0, max=100)
self.spin_3 = wx.SpinCtrl(self, wx.ID_ANY, "0", min=0, max=100)
self.button_ok = wx.Button(self, wx.ID_ANY, r"Применить")
self.button_back = wx.Button(self, wx.ID_ANY, r"Назад")
self.button_ok = wx.Button(self, ID_OK, r"Применить")
self.button_back = wx.Button(self, ID_BACK, r"Назад")

self.__set_properties()
self.__do_layout()
self.__update_ui()

self.Bind(wx.EVT_LISTBOX, self.onListbox, id=wx.ID_ANY)
self.Bind(wx.EVT_BUTTON, self.onButton, id=wx.ID_ANY)

def __set_properties(self):
self.SetTitle(r"Добавить эффект")
Expand All @@ -28,19 +38,19 @@ def __do_layout(self):
sizer_1 = wx.BoxSizer(wx.HORIZONTAL)
sizer_1.Add(self.list_box_1, 1, 0, 0)
sizer_0.Add(sizer_1, 0, wx.EXPAND, 0)
label_1 = wx.StaticText(self, wx.ID_ANY, r"Параметр 1")
label_1.SetMinSize((80, 16))
sizer_2.Add(label_1, 0, wx.ALIGN_CENTER_VERTICAL, 0)
self.label_1 = wx.StaticText(self, wx.ID_ANY, r"Параметр 1")
self.label_1.SetMinSize((80, 16))
sizer_2.Add(self.label_1, 0, wx.ALIGN_CENTER_VERTICAL, 0)
sizer_2.Add(self.spin_1, 0, 0, 0)
sizer_0.Add(sizer_2, 0, wx.EXPAND, 0)
label_2 = wx.StaticText(self, wx.ID_ANY, r"Параметр 2")
label_2.SetMinSize((80, 16))
sizer_3.Add(label_2, 0, wx.ALIGN_CENTER_VERTICAL, 0)
self.label_2 = wx.StaticText(self, wx.ID_ANY, r"Параметр 2")
self.label_2.SetMinSize((80, 16))
sizer_3.Add(self.label_2, 0, wx.ALIGN_CENTER_VERTICAL, 0)
sizer_3.Add(self.spin_2, 0, 0, 0)
sizer_0.Add(sizer_3, 0, wx.EXPAND, 0)
label_3 = wx.StaticText(self, wx.ID_ANY, r"Параметр 3")
label_3.SetMinSize((80, 16))
sizer_4.Add(label_3, 0, wx.ALIGN_CENTER_VERTICAL, 0)
self.label_3 = wx.StaticText(self, wx.ID_ANY, r"Параметр 3")
self.label_3.SetMinSize((80, 16))
sizer_4.Add(self.label_3, 0, wx.ALIGN_CENTER_VERTICAL, 0)
sizer_4.Add(self.spin_3, 0, 0, 0)
sizer_0.Add(sizer_4, 0, wx.EXPAND, 0)
sizer_5.Add(self.button_ok, 1, 0, 0)
Expand All @@ -50,3 +60,37 @@ def __do_layout(self):
sizer_0.Fit(self)
self.Layout()


def __update_ui(self):
sel = self.list_box_1.GetSelection()
par1 = par2 = par3 = ""
par1_en, par2_en, par3_en = False, False, False
if sel == 1:
par1, par2 = "Ширина ядра", "Высота ядра"
par1_en, par2_en = True, True
elif sel == 2:
par1, par2 = "Ширина ядра", "Высота ядра"
par1_en, par2_en, par3_en = True, True
elif sel == 3:
par1 = "Параметр"
par1_en = True
elif sel == 4:
par1, par2, par3 = "Параметр1", "Параметр2", "Параметр3"
par1_en, par2_en, par3_en = True, True, True
self.label_1.SetLabel(par1)
self.label_2.SetLabel(par2)
self.label_3.SetLabel(par3)
self.spin_1.Enable(par1_en)
self.spin_2.Enable(par2_en)
self.spin_3.Enable(par3_en)


def onListbox(self, event):
self.__update_ui()
event.Skip()

def onButton(self, event):
if event.Id == ID_BACK or event.Id == ID_OK:
self.Result = event.Id == ID_OK
self.Close()
event.Skip()
47 changes: 44 additions & 3 deletions engine.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import cv2 as cv
import os
import sys


def resource_path(relative):
return (sys._MEIPASS+"/" if getattr(sys, 'frozen', False) else "")+relative

def to_number(x, y=None):
try:
x = int(x)
Expand All @@ -11,20 +16,56 @@ def to_number(x, y=None):
return x


def apply_effect(frame, eff: list):
if len(eff) < 1:
return frame
eff_n = eff[0]
if eff_n == 1:
return cv.blur(frame, (eff[1], eff[2]))
elif eff_n == 2:
return cv.GaussianBlur(frame, (eff[1], eff[2]))
elif eff_n == 3:
return cv.medianBlur(frame, eff[1])
elif eff_n == 4:
return cv.bilateralFilter(frame, eff[1], eff[2], eff[3])
else:
return frame


class VideoFeed(object):
def __init__(self, filename=None, resize=False):
self.effect = [0]
self.open(filename, resize)

def open(self, filename=None, resize=False):
self.video = cv.VideoCapture(filename if filename else 0)

print(self.video.isOpened())
self.resize = resize

def opened(self):
return self.video.isOpened()

def next_frame(self, w = None, h = None):
def saveto(self, name):
fourcc = cv.VideoWriter_fourcc(*'XVID')
out = cv.VideoWriter(name,
fourcc,
self.get_fps(),
(self.get_frame_size())
)
pos = self.get_position()
self.set_position(0)
while True:
frame = self.next_frame()
if frame is None:
break
out.write(frame)
self.set_position(pos)
out.release()

def next_frame(self, w=None, h=None):
ret, frame = self.video.read()
if ret and self.effect[0] != 0:
frame = apply_effect(frame, self.effect)
if ret and self.resize and w and h:
frame = cv.resize(frame, (w, h))
return frame if ret else None
Expand All @@ -34,7 +75,7 @@ def length(self):

def get_frame_size(self):
v = self.video
return v.get(cv.CAP_PROP_FRAME_WIDTH), v.get(cv.CAP_PROP_FRAME_HEIGHT)
return int(v.get(cv.CAP_PROP_FRAME_WIDTH)), int(v.get(cv.CAP_PROP_FRAME_HEIGHT))

# <position>
def get_position(self):
Expand Down
4 changes: 2 additions & 2 deletions forms/Effects.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
# generated by wxGlade 0.9.5 on Fri May 15 18:56:35 2020
# generated by wxGlade 0.9.5 on Fri May 15 19:17:55 2020
#

import wx
Expand All @@ -19,7 +19,7 @@ def __init__(self, *args, **kwds):
# begin wxGlade: Effects.__init__
kwds["style"] = kwds.get("style", 0) | wx.CAPTION
wx.Dialog.__init__(self, *args, **kwds)
self.list_box_1 = wx.ListBox(self, wx.ID_ANY, choices=[_("Blur"), _("GaussianBlur"), _("medianBlur"), _("bilateralFilter")])
self.list_box_1 = wx.ListBox(self, wx.ID_ANY, choices=[_("--"), _("Blur"), _("GaussianBlur"), _("medianBlur"), _("bilateralFilter")])
self.spin_1 = wx.SpinCtrl(self, wx.ID_ANY, "0", min=0, max=100)
self.spin_2 = wx.SpinCtrl(self, wx.ID_ANY, "0", min=0, max=100)
self.spin_3 = wx.SpinCtrl(self, wx.ID_ANY, "0", min=0, max=100)
Expand Down
3 changes: 2 additions & 1 deletion forms/Effects.wxg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<!-- generated by wxGlade 0.9.5 on Fri May 15 18:56:33 2020 -->
<!-- generated by wxGlade 0.9.5 on Fri May 15 19:17:54 2020 -->

<application class="MyApp" encoding="UTF-8" for_version="3.0" header_extension=".h" indent_amount="4" indent_symbol="space" is_template="0" language="python" mark_blocks="1" name="app" option="0" overwrite="1" path="Effects.py" source_extension=".cpp" top_window="dialog" use_gettext="1" use_new_namespace="1">
<object class="Effects" name="dialog" base="EditDialog">
Expand All @@ -21,6 +21,7 @@
<style>wxLB_SINGLE</style>
<selection>0</selection>
<choices>
<choice>--</choice>
<choice>Blur</choice>
<choice>GaussianBlur</choice>
<choice>medianBlur</choice>
Expand Down
Loading

0 comments on commit 52afb5d

Please sign in to comment.