python-OpenCv调用IP摄像头APP

使用流程:

  1. 手机安装IP摄像头APP.
  2. 手机打开IP摄像头APP.
  3. 右上角选择 “运动检测”(这个时候你应该能看到手机摄像头打开了).
  4. 屏幕中间勾选 "RTSP服务器"点击下面的 "连接?"你会看到RTSP,MJPEG,OPUS,FLV.等的连接IP和端口.
    注:(保证手机和电脑在同一个局域网中)
  5. 在电脑浏览器输入:http://admin:admin@192.168.0.101:8081/video(你将会看到你手机摄像头内的画面).
  6. 单独输入192.168.0.101:8081/video会提示要输入账号和密码(账号密码都是admin.直接按照5输入就可以直接显示了).

python-OpenCv调用:

# 下面是python-OpenCv调用IP摄像头的方法
# 2021年12月15日21:22:27
import cv2

if __name__ == "__main__":
    # IP视频地址
    url = "rtsp://admin:admin@192.168.0.101:8554/live"
    cap = cv2.VideoCapture(url)
    while cap.isOpened():
        # Capture frame-by-frame
        ret, frame = cap.read()
        # Display the resulting frame
        cv2.imshow('frame', frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
            # When everything done, release the capture
    cap.release()
    cv2.destroyAllWindows()


  • 0
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
以下是使用PythonOpenCV调用海康工业相机并显示的步骤: 1.安装海康SDK并配置环境变量。 2.安装PythonOpenCV。 3.导入必要的库和模块。 ```python import sys from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QVBoxLayout import cv2 from HCNetSDK import * ``` 4.创建一个Qt窗口并在其中添加一个标签。 ```python class Video(QWidget): def __init__(self): super().__init__() self.label = QLabel(self) self.layout = QVBoxLayout() self.layout.addWidget(self.label) self.setLayout(self.layout) ``` 5.初始化海康SDK并登录相机。 ```python def init_camera(): # 初始化SDK if not NET_DVR_Init(): print("SDK初始化失败") sys.exit() # 登录相机 device_info = NET_DVR_DEVICEINFO_V30() device_ip = "192.168.1.64" device_port = 8000 device_username = "admin" device_password = "12345" device_id = NET_DVR_Login_V30(device_ip, device_port, device_username, device_password, device_info) if device_id < 0: print("登录相机失败") sys.exit() return device_id ``` 6.获取相机数据并将其转换为OpenCV支持的格式。 ```python def get_frame(device_id): # 获取相机数据 frame = NET_DVR_GetRealPlayImage(device_id) # 将相机数据转换为OpenCV支持的格式 frame_data = frame.contents.pBuffer frame_size = frame.contents.dwSize frame_image = np.frombuffer(frame_data, dtype=np.uint8) frame_image = frame_image.reshape((frame_size[1], frame_size[0], 4)) frame_image = cv2.cvtColor(frame_image, cv2.COLOR_BGRA2BGR) return frame_image ``` 7.在Qt窗口中显示相机数据。 ```python def show_camera(): app = QApplication(sys.argv) video = Video() video.show() device_id = init_camera() while True: frame_image = get_frame(device_id) frame_image = cv2.resize(frame_image, (640, 480)) frame_image = cv2.cvtColor(frame_image, cv2.COLOR_BGR2RGB) video.label.setPixmap(QPixmap.fromImage(QImage(frame_image.data, frame_image.shape[1], frame_image.shape[0], QImage.Format_RGB888))) if cv2.waitKey(1) & 0xFF == ord('q'): break NET_DVR_Logout(device_id) NET_DVR_Cleanup() sys.exit(app.exec_()) ``` 8.运行程序并显示相机数据。 ```python if __name__ == '__main__': show_camera() ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

探测之眼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值