Created
July 10, 2020 06:38
-
-
Save yushulx/0eb5cbc2c55452f43069545b5fc34f91 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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