Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何通过代理服务器在OpenCV中打开视频流?_Python_Opencv_Http Proxy - Fatal编程技术网

Python 如何通过代理服务器在OpenCV中打开视频流?

Python 如何通过代理服务器在OpenCV中打开视频流?,python,opencv,http-proxy,Python,Opencv,Http Proxy,有点像一个无趣的问题。我的目标是在互联网上打开一个视频流,作为OpenCV中的视频捕获对象,我需要通过代理服务器连接,而不是直接连接。我需要为每个脚本设置代理服务器(我有3-4个脚本同时运行,它们都需要使用不同的代理),因此我不能使用环境变量 我可以使用requests库设置代理并执行get请求,但如何将结果设置为cv2.VideoCapture对象?如果结果只是一个文件,我可以理解这样做,但这是一个无穷无尽的过程 我可以为每个python脚本设置一个代理服务器,然后使用OpenCV Video

有点像一个无趣的问题。我的目标是在互联网上打开一个视频流,作为OpenCV中的视频捕获对象,我需要通过代理服务器连接,而不是直接连接。我需要为每个脚本设置代理服务器(我有3-4个脚本同时运行,它们都需要使用不同的代理),因此我不能使用环境变量

我可以使用requests库设置代理并执行get请求,但如何将结果设置为cv2.VideoCapture对象?如果结果只是一个文件,我可以理解这样做,但这是一个无穷无尽的过程

我可以为每个python脚本设置一个代理服务器,然后使用OpenCV VideoCapture进行连接吗?`或者我必须使用请求包流功能并以某种方式迭代视频流的每个帧吗?我对请求包和HTTP协议都不太了解,所以如果您愿意回答(如果愿意,请提前感谢!),请以ELI5的方式回答:)。谢谢

到目前为止,我的代码是:

import cv2
import numpy as np
import requests  # <- not used right now, but I guess I should somehow?

cap = cv2.VideoCapture("https://a.traffic.cam.somewhere/mpegts") # <- this connects directly, but needs to connect via proxy instead.

# Check if the stream opened correctly.
if (cap.isOpened() == False): 
  print("\n\n\nUnable to read camera feed\n\n\n")
else:
  print("\n\n\nOpened successfully. Press Ctrl+C to stop.\n\n\n")

# here we do some OpenCV stuff to each frame

if ret == True:
  # overlay date and time to the upper corner of the frame
  frame = cv2.putText(frame,str(datetime.now()) + " EET",(50,50), cv2.FONT_HERSHEY_SIMPLEX, 1,(255,255,255),2,cv2.LINE_AA)
  out.write(frame)
  # and show that frame on the screen
  cv2.imshow('frame', cv2.resize(frame, (int(frame_width*0.5), int(frame_height*0.5))))
  if cv2.waitKey(1) & 0xFF == ord('q'):
    break

# more code
# more code
# more code
导入cv2
将numpy作为np导入
导入请求#