簡體   English   中英

如何使用openCV和python從流中逐幀獲取視頻

[英]How to get video frame by frame from stream using openCV and python

我正在使用 VLC 媒體播放器通過 http 流式傳輸 .mp4 視頻。 流媒體工作正常(我能夠使用另一個 VLC 實例附加到這個流)。 現在我想使用 OpenCV 和 python 2.7 連接到這個流並逐幀獲取視頻。

這是修改后的教程代碼(與本地文件完美配合):

<code>
import numpy as np
import cv2    
address = '10.0.0.71' # this is my stream ip address
port = 8080 # this is stream port

# should I use socket somehow?
# found this somewhere, no idea what this do
# import socket
# msocket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) 
# msocket.connect((address, port))

cap = cv2.VideoCapture('file.mp4') # how to use VideoCapture with online stream?     

# just showing video to screen
while(cap.isOpened()):
    ret, frame = cap.read()
    cv2.imshow('frame', frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

請幫忙。

http://answers.opencv.org/question/24154/how-to-using-opencv-api-get-web-video-stream/

您應該能夠僅cap = cv2.VideoCapture('yourStreamURIHere')

如果您需要登錄流,例如在 127.0.0.1 使用用戶名:hello,密碼:goodbye 的某個流:

cap = cv2.VideoCapture('http://hello:goodbye@127.0.0.1/?action=stream?otherparamshere)

我有點晚了,但我已經創建了強大的線程VidGear視頻處理 python 庫,該庫現在提供NetGear API ,專門設計用於通過 ZmQ 消息傳遞系統在網絡上的互連系統之間實時同步傳輸視頻幀。 有關使用示例,請在此處查看我的詳細答案: https : //stackoverflow.com/a/57205019/10158117

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM