-
-
Save kevincruzai/c99f646b081d4dc0468bb9874642a2f1 to your computer and use it in GitHub Desktop.
Revisions
-
n3wtron revised this gist
May 11, 2016 . 1 changed file with 7 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,11 +2,12 @@ ''' Author: Igor Maculan - [email protected] A Simple mjpg stream http server ''' import cv2 import Image import threading from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer from SocketServer import ThreadingMixIn import StringIO import time capture=None @@ -44,6 +45,10 @@ class CamHandler(BaseHTTPRequestHandler): self.wfile.write('</body></html>') return class ThreadedHTTPServer(ThreadingMixIn, HTTPServer): """Handle requests in a separate thread.""" def main(): global capture capture = cv2.VideoCapture(0) @@ -52,7 +57,7 @@ def main(): capture.set(cv2.cv.CV_CAP_PROP_SATURATION,0.2); global img try: server = ThreadedHTTPServer(('localhost', 8080), CamHandler) print "server started" server.serve_forever() except KeyboardInterrupt: -
n3wtron revised this gist
Mar 21, 2016 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,7 @@ ''' Author: Igor Maculan - [email protected] A Simple mjpg stream http server License: GPL v3 ''' import cv2 import Image -
n3wtron revised this gist
Jan 24, 2013 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -6,12 +6,10 @@ import cv2 import Image from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer import StringIO import time capture=None class CamHandler(BaseHTTPRequestHandler): def do_GET(self): if self.path.endswith('.mjpg'): -
n3wtron revised this gist
Jan 24, 2013 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ #!/usr/bin/python ''' Author: Igor Maculan - [email protected] A Simple mjpg stream http server -
n3wtron created this gist
Jan 24, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,64 @@ ''' Author: Igor Maculan - [email protected] A Simple mjpg stream http server ''' import cv2 import Image from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer import numpy import StringIO import time capture=None class CamHandler(BaseHTTPRequestHandler): def do_GET(self): if self.path.endswith('.mjpg'): self.send_response(200) self.send_header('Content-type','multipart/x-mixed-replace; boundary=--jpgboundary') self.end_headers() while True: try: rc,img = capture.read() if not rc: continue imgRGB=cv2.cvtColor(img,cv2.COLOR_BGR2RGB) jpg = Image.fromarray(imgRGB) tmpFile = StringIO.StringIO() jpg.save(tmpFile,'JPEG') self.wfile.write("--jpgboundary") self.send_header('Content-type','image/jpeg') self.send_header('Content-length',str(tmpFile.len)) self.end_headers() jpg.save(self.wfile,'JPEG') time.sleep(0.05) except KeyboardInterrupt: break return if self.path.endswith('.html'): self.send_response(200) self.send_header('Content-type','text/html') self.end_headers() self.wfile.write('<html><head></head><body>') self.wfile.write('<img src="http://127.0.0.1:8080/cam.mjpg"/>') self.wfile.write('</body></html>') return def main(): global capture capture = cv2.VideoCapture(0) capture.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, 320); capture.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, 240); capture.set(cv2.cv.CV_CAP_PROP_SATURATION,0.2); global img try: server = HTTPServer(('',8080),CamHandler) print "server started" server.serve_forever() except KeyboardInterrupt: capture.release() server.socket.close() if __name__ == '__main__': main()