forked from titos-carrasco/DSO5102P-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test5-MJPEG.py
47 lines (39 loc) · 1.45 KB
/
Test5-MJPEG.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#! /usr/bin/python3
# -*- coding: utf-8 -*-
import time
import numpy as np
import cv2
import http.server
import socketserver
from rcr.dso5102p.DSO5102P import DSO5102P
class Streamer( http.server.SimpleHTTPRequestHandler ):
def do_GET(self):
self.send_response( 200 )
self.send_header( "Content-type", "multipart/x-mixed-replace; boundary=--boundary" )
self.end_headers()
while(True):
try:
img = self.dso.Screenshot()
#img = cv2.applyColorMap( img, cv2.COLORMAP_HOT )
_, data = cv2.imencode( '.JPEG', img, ( cv2.IMWRITE_JPEG_QUALITY, 80 ) )
self.wfile.write( b"--boundary\r\n" )
self.wfile.write( b"Content-Type: image/jpeg\r\n" )
self.wfile.write( b"Content-length: " + bytes( str( len( data) ).encode() ) )
self.wfile.write( b"\r\n" )
self.end_headers()
self.wfile.write( data )
self.wfile.write( b"\r\n\r\n\r\n" )
#time.sleep( 0.100 )
except Exception as e:
print( e )
break
# show time
if __name__ == '__main__':
try:
print( "Inicializando DSO5102P" )
Streamer.dso = DSO5102P( 0x049f, 0x505a, False )
print( "Levantando HTTP Server" )
server = socketserver.TCPServer( ('', 8080), Streamer )
server.serve_forever()
except Exception as e:
print( e )