Skip to content

Commit

Permalink
Add the first three worked examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
ohookins committed Jul 16, 2011
1 parent 0253502 commit 08c6f2c
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
15 changes: 15 additions & 0 deletions firstprogram.py
@@ -0,0 +1,15 @@
#!/usr/bin/python

import sys
from opencv import highgui

def show(filename):
img = highgui.cvLoadImage(filename)
highgui.cvNamedWindow("Example1", highgui.CV_WINDOW_AUTOSIZE)
highgui.cvShowImage("Example1", img)
highgui.cvWaitKey(0)
highgui.cvDestroyWindow("Example1")

if __name__ == "__main__":
show(sys.argv[1])
sys.exit(0)
25 changes: 25 additions & 0 deletions secondprogram.py
@@ -0,0 +1,25 @@
#!/usr/bin/python

import sys
from opencv import highgui

def showavi(filename):
highgui.cvNamedWindow("Example2", highgui.CV_WINDOW_AUTOSIZE)
capture = highgui.cvCreateFileCapture(filename)

while True:
frame = highgui.cvQueryFrame(capture)
if not frame:
break
highgui.cvShowImage("Example2", frame)

c = highgui.cvWaitKey(100)
if c == '\x1b': # escape key
break

highgui.cvReleaseCapture(capture)
highgui.cvDestroyWindow("Example2")

if __name__ == "__main__":
showavi(sys.argv[1])
sys.exit(0)
37 changes: 37 additions & 0 deletions thirdprogram.py
@@ -0,0 +1,37 @@
#!/usr/bin/python

import sys
from opencv import highgui

capture = None
slider_pos = 0

def on_trackbar_slide(position):
highgui.cvSetCaptureProperty(capture, highgui.CV_CAP_PROP_POS_FRAMES, position)

def showavi(filename):
highgui.cvNamedWindow("Example3", highgui.CV_WINDOW_AUTOSIZE)
global capture
capture = highgui.cvCreateFileCapture(filename)

frames = int(highgui.cvGetCaptureProperty(capture, highgui.CV_CAP_PROP_FRAME_COUNT))

if frames != 0:
highgui.cvCreateTrackbar("Position", "Example3", slider_pos, frames, on_trackbar_slide)

while True:
frame = highgui.cvQueryFrame(capture)
if not frame:
break
highgui.cvShowImage("Example3", frame)

c = highgui.cvWaitKey(100)
if c == '\x1b': # escape key
break

highgui.cvReleaseCapture(capture)
highgui.cvDestroyWindow("Example3")

if __name__ == "__main__":
showavi(sys.argv[1])
sys.exit(0)

0 comments on commit 08c6f2c

Please sign in to comment.