[英]How to stream OpenCv image from webcam to http server
I am attempting to send an image from a webcam on a RasPi to an Http server, so that when I open it on my Robot I can actually get the image. 我试图将图像从RasPi上的网络摄像头发送到Http服务器,这样当我在我的机器人上打开它时,我实际上可以获得图像。 I know how to use openCV in a window, and I have been able to create a server I can open in my browser, my question is simply how to display the openCV feed on said server.
我知道如何在一个窗口中使用openCV,我已经能够创建一个我可以在浏览器中打开的服务器,我的问题就是如何在所述服务器上显示openCV feed。
FYI, I am trying to get this working on a computer before fighting with the RasPi, so the RasPi is not currently an issue I am concerned with. 仅供参考,我想在与RasPi战斗之前在计算机上工作,因此RasPi目前不是我关心的问题。
#Current Code
import cv2
from http.server import BaseHTTPRequestHandler, HTTPServer
import time
from io import StringIO
import PIL
from PIL import Image
hostName = 'localhost'
hostPort = 7153
#run camera
cap = cv2.VideoCapture(0)
def updateCamFeed():
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi', fourcc, 20.0, (640, 480))
while True:
ret, frame = cap.read()
class MyServer(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write(bytes("<html><head><title>WebCam Display</title>
</head>", "utf-8"))
self.wfile.write(bytes("<body><p><a href=\"output.avi\">Image</a>
</p>", "utf-8"))
self.wfile.write(bytes("<p>It Worked!!!!! %s</p>" % self.path,
"utf-8"))
self.wfile.write(bytes("</body></html>", "utf-8"))
def main():
# initialize server
myServer = HTTPServer((hostName, hostPort), MyServer)
print(time.asctime(), "Server Starts - %s:%s" % (hostName, hostPort))
myServer.serve_forever()
updateCamFeed()
if __name__ == '__main__':
main()
This will send the file to the server, but will not display it in a window 这会将文件发送到服务器,但不会在窗口中显示
I meant opening the server on my computer, which is connected to the mentioned robot. 我的意思是在我的计算机上打开服务器,该计算机连接到所提到的机器人。 Just trying to help with any confusion
只是想帮助解决任何困惑
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.