如何使用azure IoEdge从IoEdge模块访问摄像头模块

2024-04-25 19:43:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我在docker文件中使用以下代码进行视频流

import numpy as np
import cv2
cap = cv2.VideoCapture(0)
# Define the codec and create VideoWriter object
#fourcc = cv.VideoWriter_fourcc(*'XVID')
total_frame=0
while cap.isOpened():
    ret, frame = cap.read()
    print(ret)
    if not ret:
        print("Can't receive frame (stream end?). Exiting ...")
        break
    #frame = cv.flip(frame, 0)

    #video_writer = cv2.VideoWriter(time_string, fourcc, 30.0, (1280, 720))
    # write the flipped frame


# Release everything if job is finished
cap.release()
#cv2.destroyAllWindows()

`

我将此dockerfile用于上述代码

FROM ubuntu

# Install dependencies
RUN apt-get update && \
  apt-get install -yq \ 
    python3 \
    python3-pip \   
  && apt-get clean && rm -rf /var/lib/apt/lists/*


RUN pip3 install --upgrade pip 
RUN pip3 install imutils
RUN pip3 install azure-iot-device
RUN pip3 install opencv-contrib-python

WORKDIR /main/

COPY main .

CMD ["python3", "/main/main.py"]

我可以使用docker run--device/dev/video0 image访问主机上的视频源 但当我将摄像头部署为IoEdge模块时,我无法访问它?请告诉我如何从hostsystem上的IoEdge模块访问视频源。cv2.VideoCapture(0)的位置是cv2.VideoCapture('/dev/video0')


1条回答
网友
1楼 · 发布于 2024-04-25 19:43:35

对于任何容器,包括IoT边缘模块,您都需要向容器公开/dev/videoX。对于IoT边缘模块,这是通过容器创建选项完成的

在此处搜索/dev/video0:https://kevinsaye.wordpress.com/2018/04/16/creating-an-opencv-module-for-iot-edge/以查看它是如何完成的

相关问题 更多 >