# -*- coding: utf-8 -*-
 """
 Created on Fri Jan 3 21:06:22 2014@author: duan
 """import numpy as np
 import cv2cap = cv2.VideoCapture(0)
width=cap.get(3)
 height=cap.get(4)
 print width
 print heightret=cap.set(3,320)
 ret=cap.set(4,240)
 width=cap.get(3)
 height=cap.get(4)
 print width
 print heightif cap.isOpened():
   while(True):
     # Capture frame-by-frame
     ret, frame = cap.read()
     if ret==True:
       # Our operations on the frame come here
       gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)      # Display the resulting frame
       cv2.imshow('frame',gray)
     key=cv2.waitKey(1)
     if key & 0xFF == ord('q'):
      break
     elif key & 0xFF == ord('a'):
      ret=cap.set(3,640)
      ret=cap.set(4,480)
     elif key & 0xFF == ord('s'):
      ret=cap.set(3,320)
      ret=cap.set(4,240)
   # When everything done, release the capture
   cap.release()
   cv2.destroyAllWindows()
 else:
   print 'cap is not Opened!'
你可以使用函数cap.get(propId) 来获得视频的一些参数信息。这里
 propId 可以是0 到18 之间的任何整数。每一个数代表视频的一个属性,见
 下表
 其中的一些值可以使用cap.set(propId,value) 来修改,value 就是
 你想要设置成的新值。
 例如,我可以使用cap.get(3) 和cap.get(4) 来查看每一帧的宽和高。
 默认情况下得到的值是640X480。但是我可以使用ret=cap.set(3,320)
 和ret=cap.set(4,240) 来把宽和高改成320X240。