官术网_书友最值得收藏!

Running the app

To run the application, we will turn to the chapter1.py script. Follow these steps to do so:

  1. We first start by importing all the necessary modules:
import wx
import cv2
import numpy as np
  1. We will also have to import a generic GUI layout (from wx_gui) and all the designed image effects (from tools):
from wx_gui import BaseLayout
from tools import apply_hue_filter
from tools import apply_rgb_filters
from tools import load_img_resized
from tools import spline_to_lookup_table
from tools import cartoonize
from tools import pencil_sketch_on_canvas
  1. OpenCV provides a straightforward way to access a computer's webcam or camera device. The following code snippet opens the default camera ID (0) of a computer using cv2.VideoCapture:
def main(): 
    capture = cv2.VideoCapture(0) 
  1. In order to give our application a fair chance to run in real time, we will limit the size of the video stream to 640 x 480 pixels:
    capture.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
  1. Then, the capture stream can be passed to our GUI application, which is an instance of the FilterLayout class:
    # start graphical user interface
app = wx.App()
layout = FilterLayout(capture, title='Fun with Filters')
layout.Center()
layout.Show()
app.MainLoop()

After we create FilterLayout, we center the layout, so it appears in the center of the screen. And we call Show() to actually show the layout. Finally, we call app.MainLoop(), so the application starts working, receiving, and processing events.

The only thing left to do now is to design the said GUI.

主站蜘蛛池模板: 互助| 彩票| 湖北省| 岐山县| 宁津县| 东至县| 山西省| 荃湾区| 佛冈县| 江城| 宁阳县| 洛隆县| 沁阳市| 青龙| 吉安市| 偏关县| 新乡县| 横山县| 基隆市| 垣曲县| 兰西县| 洪江市| 泸西县| 盐城市| 澄城县| 门头沟区| 乌鲁木齐市| 天全县| 新闻| 泊头市| 白山市| 安吉县| 门头沟区| 宁国市| 阳原县| 乐山市| 板桥市| 娱乐| 肃南| 灵寿县| 喀什市|