Skip to content

Instantly share code, notes, and snippets.

@yushulx
Created July 10, 2020 06:38
Show Gist options
  • Save yushulx/0eb5cbc2c55452f43069545b5fc34f91 to your computer and use it in GitHub Desktop.
Save yushulx/0eb5cbc2c55452f43069545b5fc34f91 to your computer and use it in GitHub Desktop.
import http.server
import socketserver
class MyHandler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
if self.path == '/':
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write(bytes(pageData, "utf8"))
elif self.path.startswith('/image'):
self.send_response(200)
self.send_header("Content-type", "image/jpeg")
self.end_headers()
ret, frame = cap.read()
_, jpg = cv2.imencode(".jpg", frame)
self.wfile.write(jpg)
else:
self.send_response(404)
with socketserver.TCPServer(("", PORT), MyHandler) as httpd:
print("Serving at port ", PORT)
try:
httpd.serve_forever()
except:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment