jetsonnano 获取usb摄像头 灰度识别 视频显示窗口设置

该代码示例展示了如何用Python和OpenCV库获取USB摄像头的视频流,调整帧率和窗口位置,并进行灰度转换、色彩空间变换以及窗口大小设置。通过cv2.VideoCapture()打开摄像头,然后使用cv2.cvtColor()进行颜色空间转换,如灰度、LAB、HLS、HSV和XYZ。同时,代码还演示了如何调整窗口的位置和大小。
摘要由CSDN通过智能技术生成

1.获取usb摄像头

import cv2

cam = cv2.VideoCapture()
cam.open( 0, apiPreference = cv2.CAP_V4L2)
cam.set(cv2.CAP_PROP_FRAME_WIDTH,640)
cam.set(cv2.CAP_PROP_FRAME_HEIGHT,480)
cam.set(cv2.CAP_PROP_FOURCC,cv2.VideoWriter_fourcc(*'MJPG'))
cam.set(cv2.CAP_PROP_FPS,60)
while True:
    ret,frame = cam.read()
    if ret == False:
        break
    cv2.imshow('USB Camera' , frame)
    if cv2.waitKey(1) == ord('q'):
        break
    print(cam.get(3),cam.get(4),cam.get(5),cam.get(6))
cam.release()
cv2.destroyAllWindows()

2.灰度识别  和 窗口设置位置设置

import cv2
cam = cv2.VideoCapture()
cam.open( 0, apiPreference = cv2.CAP_V4L2)
cam.set(cv2.CAP_PROP_FRAME_WIDTH,640)
cam.set(cv2.CAP_PROP_FRAME_HEIGHT,480)
cam.set(cv2.CAP_PROP_FOURCC,cv2.VideoWriter_fourcc(*'MJPG'))
cam.set(cv2.CAP_PROP_FPS,60)
while True:
    ret,frame = cam.read()
    if ret == False:
        break
    cv2.imshow('USB Camera' , frame)
    cv2.moveWindow('USB Camera',0,0)
    gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
    cv2.imshow('gray Video',gray)
    cv2.moveWindow('gray Video',0,540)
    LAB = cv2.cvtColor(frame,cv2.COLOR_BGR2LAB)
    cv2.imshow('LAB Video',LAB)
    cv2.moveWindow('LAB Video',700,0)
    HLS = cv2.cvtColor(frame,cv2.COLOR_BGR2HLS)
    cv2.imshow('HLS Video',HLS)
    cv2.moveWindow('HLS Video',700,540)
    HSV = cv2.cvtColor(frame,cv2.COLOR_BGR2HSV)
    cv2.imshow('HSV Video',HSV)
    cv2.moveWindow('HSV Video',1440,540)
    XYZ = cv2.cvtColor(frame,cv2.COLOR_BGR2XYZ)
    cv2.imshow('XYZ Video',XYZ)
    cv2.moveWindow('XYZ Video',1440,0)
    if cv2.waitKey(1) == ord('q'):
        break
    print(cam.get(3),cam.get(4),cam.get(5),cam.get(6))
cam.release()
cv2.destroyAllWindows()

3.窗口大小设置

import cv2

cam = cv2.VideoCapture()
cam.open( 0, apiPreference = cv2.CAP_V4L2)
cam.set(cv2.CAP_PROP_FRAME_WIDTH,640)
cam.set(cv2.CAP_PROP_FRAME_HEIGHT,480)
cam.set(cv2.CAP_PROP_FOURCC,cv2.VideoWriter_fourcc(*'MJPG'))
#cam.set(cv2.CAP_PROP_FPS,60)
while True:
    ret,frame = cam.read()
    if ret == False:
        break
    cv2.imshow('USB Camera' , frame)
    cv2.moveWindow('USB Camera',0 , 0)
    gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
    frameSmall = cv2.resize(gray,(320,240))
    cv2.imshow('gray' , frameSmall)
    cv2.moveWindow('gray' , 720, 0)
    if cv2.waitKey(1) == ord('q'):
        break
    print(cam.get(3),cam.get(4),cam.get(5),cam.get(6))
cam.release()
cv2.destroyAllWindows()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值