0
点赞
收藏
分享

微信扫一扫

opencv打开TX2板载摄像头的正确方式

1. 因TX2的板载摄像头和USB摄像头的打开方式不一样,并不能命令使用如下开启板载摄像头。

cap = cv2.VideoCapture(0)

2. 故使用带有TX2参数的代码,即可成功开启摄像头

import cv2

def arg2(width,height):
    gst_str = ('nvarguscamerasrc ! '
                'video/x-raw(memory:NVMM), '
                'width=(int)640, height=(int)480, '
                'format=(string)NV12, framerate=(fraction)30/1 ! '
                'nvvidconv flip-method=2 ! '
                'video/x-raw, width=(int){}, height=(int){}, '
                'format=(string)BGRx ! '
                'videoconvert ! appsink').format(width, height)
    return gst_str


def open_2():
    path = arg2(640, 480)
    print("2222path",path)
    cap = cv2.VideoCapture(path)
    if not cap.isOpened():
       print('Failed to open camera!2222222222222222')
    return cap

def openVideo(cap):
    while True:  # 进入无限循环
        ret, frame = cap.read()  # 将摄像头拍到的图像作为frame值
        cv2.imshow('frame', frame)  # 将frame的值显示出来 有两个参数 前一个是窗口名字,后面是值
        c = cv2.waitKey(1)  # 判断退出的条件 当按下'Q'键的时候呢,就退出
        if c == ord('q'):
            break
    cap.release()  # 常规操作
    cv2.destroyAllWindows()

if __name__ == '__main__':

    cap_2 = open_2()
    openVideo(cap_2)
    # openVideo(cap_2)

本文参考:

opencv之打开摄像头、边缘检测_早睡的叶子的博客-CSDN博客_opencv打开摄像头

举报

相关推荐

0 条评论