opencv连接网络摄像头

import cv2
import numpy as np


# http://admin:[email protected]:8081
# url = 'rtsp://admin:[email protected]:554//Streaming/Channels/2'
url = 0
cap = cv2.VideoCapture(url)
while cap.isOpened():
    # print('xxx')
    ret, frame = cap.read()
    if not ret:
        break    
    cv2.imshow('frame', frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

如果本地多个USB摄像头
查看摄像头编号
安装v4l-utils

sudo apt install v4l-utils

查看共有几个

ls  /dev/video*

在这里插入图片描述

# 修改顶部代码
# 01234 每个试一次就知道摄像头都属于哪个了
cv2.VideoCapture(0)

你可能感兴趣的:(opencv-python,学习笔记,opencv)