VideoCapture_read.py 使用ret=cap.set(3,320)和ret=cap.set(4,240) 来把宽和高改成320X240
2016-12-11 14:45
543 查看
# -*- 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。
"""
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。
相关文章推荐
- VideoCapture_read.py cap.read() 返回一个布尔值(True/False)
- build_mips/makedevs-host/makedevs.c:366:6: 错误: 变量‘ret’被设定但未被使用 [-Werror=unused-but-set-variable]
- 在linux内核中操作文件的方法--使用get_fs()和set_fs(KERNEL_DS) .bin file write/read
- 从文件中播放视频 VideoCapture_read_avi.py
- VideoCapture_read.py 用摄像头捕获视频
- 在code中尽量不要直接使用READ_ONCE和WRITE_ONCE。反而应该用atomic_read和atomic_set 替换
- 使用SetupIterateCabinet函数导出.cap文件
- UEditor使用及Cannot set property 'innerHTML' of undefined 及Cannot read property 'replace' of undefine
- 使用set时需要考虑的一点
- J2ME小tip:setClip方法的使用
- 使用hibernate心得——字符串超长的解决办法(setCharacterStream出现顺序问题)
- Application.SetCompatibleTextRenderingDefault的作用及使用方法
- 使用'VRM_SET_VALUES'函数在selection屏幕上建一个Combobox控件示例
- read-Atleap-4-标志库的使用
- 使用 SetCustomizedString汉化UltraWinGrid的筛选
- 在编写存储过程时使用 Set NoCount On
- ABAP:Function 之 Read_Text函数的使用方法
- 看你知道不知道之-使用SET NOCOUNT优化存储过程
- D9下面使用DelforEx出现 "File or buffer is read only, or not yet saved"的处理
- SetComputerNameEx在C#中的使用说明