2013年2月14日星期四

opencv&python - camera

    Here is an example of capturing video from camera and storing the frames in a NumPy array.


01 from cv2 import *
02 
03 # set up video capture
04 cap = VideoCapture(0)
05 namedWindow("video_test")
06 
07 #while True:  
08 #    ret, im = cap.read()
09 #    imshow("video_test", im)
10 #    key = waitKey(10) # delay in milliseconds
11 #    if key == 27: # 'esc'
12 #        break
13 #    if key == 32: # ' ' save the frame
14 #        imwrite("video_capture.jpg", im)
15 
16 # get frame and store in a NumPy array
17 frames = []
18 while True:
19     ret, im = cap.read()
20     imshow("video_test", im)
21     frames.append(im)
22     if waitKey(10) == 27:
23         break
24 import numpy
25 frames = numpy.array(frames)
26 
27 # check the sizes
28 print(im.shape)
29 # (number of frames, height, width, 3)
30 print(frames.shape)

没有评论:

发表评论