Mercurial Hosting > traffic-intelligence
comparison python/cvutils.py @ 149:0f552c8b1650
added python function to play video
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Thu, 01 Sep 2011 18:33:38 -0400 |
parents | 2bf5b76320c0 |
children | 404f3cade05f |
comparison
equal
deleted
inserted
replaced
148:ad21db62b785 | 149:0f552c8b1650 |
---|---|
1 #! /usr/bin/env python | 1 #! /usr/bin/env python |
2 '''Image/Video utilities''' | 2 '''Image/Video utilities''' |
3 | 3 |
4 import Image, ImageDraw # PIL | 4 import Image, ImageDraw # PIL |
5 try: | 5 try: |
6 import cv | 6 import cv,cv2 |
7 opencvExists = True | 7 opencvExists = True |
8 except ImportError: | 8 except ImportError: |
9 print('OpenCV library could not be loaded') | 9 print('OpenCV library could not be loaded') |
10 opencvExists = False | 10 opencvExists = False |
11 from sys import stdout | 11 from sys import stdout |
54 cvmat = cv.CreateMat(a.shape[0], a.shape[1], t) | 54 cvmat = cv.CreateMat(a.shape[0], a.shape[1], t) |
55 for i in range(cvmat.rows): | 55 for i in range(cvmat.rows): |
56 for j in range(cvmat.cols): | 56 for j in range(cvmat.cols): |
57 cvmat[i,j] = a[i,j] | 57 cvmat[i,j] = a[i,j] |
58 return cvmat | 58 return cvmat |
59 | |
60 def playVideo(filename): | |
61 capture = cv2.VideoCapture(filename) | |
62 if capture.isOpened(): | |
63 key = -1 | |
64 while key!= 1048689: # 'q' | |
65 ret, img = capture.read() | |
66 if ret: | |
67 cv2.imshow('frame', img) | |
68 key = cv2.waitKey(5) | |
69 | |
59 | 70 |
60 def printCvMat(cvmat, out = stdout): | 71 def printCvMat(cvmat, out = stdout): |
61 '''Prints the cvmat to out''' | 72 '''Prints the cvmat to out''' |
62 for i in xrange(cvmat.rows): | 73 for i in xrange(cvmat.rows): |
63 for j in xrange(cvmat.cols): | 74 for j in xrange(cvmat.cols): |