get_video

程序:

#!/usr/bin/env python3
# -*-coding:GBK -*- 
# author: diyue time:2019/10/22
# 功能:调用摄像头,并实现图像灰度化,‘q’键退出

import cv2

cap = cv2.VideoCapture(0)

if cap.isOpened():
    # check the cap is open
    print('yes')
# ret = cap.set(3, 400)
# w = cap.get(3)
# h = cap.get(4)
# print(w)
# print(h)

while True:
    ret, frame = cap.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    cv2.resizeWindow('demo', 500, 500)  # create one window ,w=h=500
    # get one image and change to another form image,such as color to gray
    cv2.imshow('demo', gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

注释:

# author: diyue time:2019/10/22
1.键盘输入判定
import keyboard
while True:
    if keyboard.is_pressed('k'):
        print('oojj')
        break

2.按键判定,关闭图像显示
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
    #'q'键退出,原理还没有理解透

3.cap.get()
    功能:获取窗口参数,get()参数值从0-18代表不同参数,如34表示每一帧的宽高,百度具体内容
    该函数应用于,设备获取之后,即cap = cv2.VideoCapture(0) 之后

4.cap.set(3,320)
    功能:设置摄像头参数,(3,320)表示将摄像头宽度分辨率设置为320;(4,320)为将高度的分辨率设置为320

5.cv2.resizeWindow('demo', 500, 500)  # create one window ,w=h=500
    功能:新建窗口


参考:
https://blog.csdn.net/Danta_psq/article/details/88560172
http://www.voidcn.com/article/p-gxnwjbth-eo.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值