-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathptr.py
executable file
·60 lines (45 loc) · 1.56 KB
/
ptr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python
import wx
import cv2.cv as cv
class WebcamPlayback(wx.Panel):
TIMER_PLAY_ID = 101
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id)
self.parent = parent
self.capture = cv.CaptureFromCAM(0)
frame = cv.QueryFrame(self.capture)
self.SetSize((frame.width, frame.height))
self.Bind(wx.EVT_PAINT, self.onPaint)
self.Bind(wx.EVT_SIZE, self.OnSize)
self.frame_timer = wx.Timer(self, self.TIMER_PLAY_ID)
wx.EVT_TIMER(self, self.TIMER_PLAY_ID, self.onNextFrame)
self.frame_timer.Start(25)
self.SetBackgroundColour(wx.BLUE)
self.Show(True)
def onPaint(self, evt):
frame = cv.QueryFrame(self.capture)
if frame:
cv.CvtColor(frame, frame, cv.CV_BGR2RGB)
img = wx.EmptyImage(frame.width , frame.height)
img.SetData(frame.tostring())
bmp = wx.BitmapFromImage(img)
wx.BufferedPaintDC(self, bmp)
def OnSize(self, event):
self.Refresh()
def onNextFrame(self, evt):
self.Refresh()
evt.Skip()
class MainWindow(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, -1, title)
hbox = wx.BoxSizer(wx.HORIZONTAL)
vbox = wx.BoxSizer(wx.VERTICAL, )
wp = WebcamPlayback(self, -1)
wp.SetSizer(vbox)
self.Centre()
self.Show(True)
if __name__=="__main__":
app = wx.App()
app.SetTopWindow(MainWindow(None, -1, 'ptr'))
app.RestoreStdio()
app.MainLoop()