VideoCapture_read.py 使用ret=cap.set(3,320)和ret=cap.set(4,240) 来把宽和高改成320X240

# -*- coding: utf-8 -*-
"""
Created on Fri Jan 3 21:06:22 2014

@author: duan
"""

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

width=cap.get(3)
height=cap.get(4)
print width
print height

ret=cap.set(3,320)
ret=cap.set(4,240)
width=cap.get(3)
height=cap.get(4)
print width
print height

if 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。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值