我如何从网址获取直播流?

问题描述 投票:1回答:2

我正在使用RPi-cam-web-interface和pi相机,raspberry pi不断将图像投射到链接,我想在我的计算机上使用opencv处理该图像。

这是我使用的senddex建议的link软件。

这是一个link到sentdex的视频。

用于从中提取图像的流式URL就是它的外观,即从中提取图像的URL。

python opencv urllib
2个回答
0
投票

您是否尝试过在VideoCapture中传递您的网址,如下所示:

cap = cv2.VideoCapture()
cap.opne("Your_URL")

0
投票

如果您可以将您的RPI链接放入VLC播放器,它应该适用于此小部件。您可以使用cv2.videoCapture()从网址流式传输。将rtsp_stream_link更改为您的RPI URL。

from threading import Thread
import cv2

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

        # Default resolutions of the frame are obtained (system dependent)
        self.frame_width = int(self.capture.get(3))
        self.frame_height = int(self.capture.get(4))

        # Set up codec and output video settings
        self.codec = cv2.VideoWriter_fourcc('M','J','P','G')
        self.output_video = cv2.VideoWriter('output.avi', self.codec, 30, (self.frame_width, self.frame_height))

        # 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:
            cv2.imshow('frame', self.frame)

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

    def save_frame(self):
        # Save obtained frame into video output file
        self.output_video.write(self.frame)

if __name__ == '__main__':
    rtsp_stream_link = 'your stream link!'
    video_stream_widget = RTSPVideoWriterObject(rtsp_stream_link)
    while True:
        try:
            video_stream_widget.show_frame()
            #video_stream_widget.save_frame()
        except AttributeError:
            pass

推荐问答