久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用 OpenCV cv2.VideoCapture 在 Python 中從 IP 攝像機進

Video Streaming from IP Camera in Python Using OpenCV cv2.VideoCapture(使用 OpenCV cv2.VideoCapture 在 Python 中從 IP 攝像機進行視頻流傳輸)
本文介紹了使用 OpenCV cv2.VideoCapture 在 Python 中從 IP 攝像機進行視頻流傳輸的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試從 IP 攝像機獲取 Python 中的視頻流,但出現錯誤.我正在使用 Pycharm IDE.

I am trying to get video stream in python from IP camera but i am getting an error. I am Using Pycharm IDE.

import cv2
scheme = '192.168.100.23'


host = scheme
cap = cv2.VideoCapture('http://admin:Ebmacs8485867@'+host+':81/web/admin.html')

while True:
    ret, frame = cap.read()

    # Place options to overlay on the video here.
    # I'll go over that later.

    cv2.imshow('Camera', frame)

    k = cv2.waitKey(0) & 0xFF
    if k == 27:  # esc key ends process
        cap.release()
        break
cv2.destroyAllWindows()

Error:
"E:Digital Image ProcessingpythonReadingAndDisplayingImagesvenvScriptspython.exe" "E:/Digital Image Processing/python/ReadingAndDisplayingImages/ReadandDisplay.py"
Traceback (most recent call last):
  File "E:/Digital Image Processing/python/ReadingAndDisplayingImages/ReadandDisplay.py", line 14, in <module>
    cv2.imshow('Camera', frame)
cv2.error: OpenCV(4.0.1) C:projectsopencv-pythonopencvmoduleshighguisrcwindow.cpp:352: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'

warning: Error opening file (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:901)
warning: http://admin:Ebmacs8485867@192.168.100.23:81/web/admin.html (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:902)

推薦答案

由于流鏈接無效,您很可能會收到該錯誤.將您的流鏈接插入 VLC 播放器以確認它正在工作.這是一個使用 OpenCV 和 cv2.VideoCapture.read() 的 IP 攝像機視頻流小部件.由于 read() 是一個阻塞操作,因此此實現使用線程來獲取不同線程中的幀.通過將此操作放在僅專注于獲取幀的單獨操作中,它可以通過減少 I/O 延遲來提高性能.我使用了自己的 IP 攝像機 RTSP 流鏈接.將 stream_link 更改為您自己的 IP 攝像頭鏈接.

You're most likely getting that error due to an invalid stream link. Insert your stream link into VLC player to confirm it is working. Here's a IP camera video streaming widget using OpenCV and cv2.VideoCapture.read(). This implementation uses threading for obtaining frames in a different thread since read() is a blocking operation. By putting this operation into a separate that that just focuses on obtaining frames, it improves performance by I/O latency reduction. I used my own IP camera RTSP stream link. Change stream_link to your own IP camera link.

根據您的 IP 攝像機,您的 RTSP 流鏈接會有所不同,這是我的一個示例:

Depending on your IP camera, your RTSP stream link will vary, here's an example of mine:

rtsp://username:password@192.168.1.49:554/cam/realmonitor?channel=1&subtype=0
rtsp://username:password@192.168.1.45/axis-media/media.amp

代碼

from threading import Thread
import cv2

class VideoStreamWidget(object):
    def __init__(self, src=0):
        # Create a VideoCapture object
        self.capture = cv2.VideoCapture(src)

        # Start the thread to read frames from the video stream
        self.thread = Thread(target=self.update, args=())
        self.thread.daemon = True
        self.thread.start()

    def update(self):
        # Read the next frame from the stream in a different thread
        while True:
            if self.capture.isOpened():
                (self.status, self.frame) = self.capture.read()

    def show_frame(self):
        # Display frames in main program
        if self.status:
            self.frame = self.maintain_aspect_ratio_resize(self.frame, width=600)
            cv2.imshow('IP Camera Video Streaming', self.frame)

        # Press Q on keyboard to stop recording
        key = cv2.waitKey(1)
        if key == ord('q'):
            self.capture.release()
            cv2.destroyAllWindows()
            exit(1)

    # Resizes a image and maintains aspect ratio
    def maintain_aspect_ratio_resize(self, image, width=None, height=None, inter=cv2.INTER_AREA):
        # Grab the image size and initialize dimensions
        dim = None
        (h, w) = image.shape[:2]

        # Return original image if no need to resize
        if width is None and height is None:
            return image

        # We are resizing height if width is none
        if width is None:
            # Calculate the ratio of the height and construct the dimensions
            r = height / float(h)
            dim = (int(w * r), height)
        # We are resizing width if height is none
        else:
            # Calculate the ratio of the 0idth and construct the dimensions
            r = width / float(w)
            dim = (width, int(h * r))

        # Return the resized image
        return cv2.resize(image, dim, interpolation=inter)

if __name__ == '__main__':
    stream_link = 'your stream link!'
    video_stream_widget = VideoStreamWidget(stream_link)
    while True:
        try:
            video_stream_widget.show_frame()
        except AttributeError:
            pass

這篇關于使用 OpenCV cv2.VideoCapture 在 Python 中從 IP 攝像機進行視頻流傳輸的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 91在线观看免费视频 | 中文字幕免费视频 | 欧美国产精品一区二区三区 | 91中文在线观看 | 亚洲精品www久久久 www.蜜桃av | 久久av一区二区三区 | 日本久久久久久 | 国产在线视频一区二区董小宛性色 | 欧美色图综合网 | 欧美一区二区黄 | 久久久久91 | 色在线视频网站 | 日韩中文字幕一区 | 麻豆av在线免费观看 | 成人精品鲁一区一区二区 | 性高湖久久久久久久久aaaaa | 国产精品亚洲综合 | h在线看| 国产在线1| 国产九九九九 | 国产精品免费一区二区三区四区 | 亚洲成av人片在线观看无码 | 久久久www成人免费无遮挡大片 | 中文字幕av网 | 91精品久久久久久久99 | 国产精品一区久久久 | 久久99精品国产自在现线小黄鸭 | 国产一区二区在线免费观看 | 黄色在线免费播放 | 黄色骚片 | 久久综合国产精品 | 99reav| 99精品久久久久 | 久久91av| 亚洲综合在线一区二区 | 五月婷婷视频 | 日韩一区二区三区在线 | 性色综合| 精品国产一区二区三区性色av | 亚洲国产一区二区三区 | 国产精品1区2区 |