mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Update mjpeg streaming example.
This commit is contained in:
parent
ed9133e447
commit
ad585caccb
@ -4,12 +4,12 @@
|
|||||||
# (IE and Chrome do not work). Just input your network SSID and KEY and then
|
# (IE and Chrome do not work). Just input your network SSID and KEY and then
|
||||||
# connect to the IP address/port printed out from ifconfig.
|
# connect to the IP address/port printed out from ifconfig.
|
||||||
|
|
||||||
import sensor, image, time, network, usocket
|
import sensor, image, time, network, usocket, sys
|
||||||
|
|
||||||
SSID='' # Network SSID
|
SSID='' # Network SSID
|
||||||
KEY='' # Network key
|
KEY='' # Network key
|
||||||
HOST = '' # Use first available interface
|
HOST = '' # Use first available interface
|
||||||
PORT = 8000 # Arbitrary non-privileged port
|
PORT = 8080 # Arbitrary non-privileged port
|
||||||
|
|
||||||
# Reset sensor
|
# Reset sensor
|
||||||
sensor.reset()
|
sensor.reset()
|
||||||
@ -19,7 +19,7 @@ sensor.set_contrast(1)
|
|||||||
sensor.set_brightness(1)
|
sensor.set_brightness(1)
|
||||||
sensor.set_saturation(1)
|
sensor.set_saturation(1)
|
||||||
sensor.set_gainceiling(16)
|
sensor.set_gainceiling(16)
|
||||||
sensor.set_framesize(sensor.QVGA)
|
sensor.set_framesize(sensor.QQVGA)
|
||||||
sensor.set_pixformat(sensor.GRAYSCALE)
|
sensor.set_pixformat(sensor.GRAYSCALE)
|
||||||
|
|
||||||
# Init wlan module and connect to network
|
# Init wlan module and connect to network
|
||||||
@ -40,32 +40,40 @@ s.listen(5)
|
|||||||
# Set timeout to 1s
|
# Set timeout to 1s
|
||||||
s.settimeout(1.0)
|
s.settimeout(1.0)
|
||||||
|
|
||||||
print ('Waiting for connections..')
|
def start_streaming(s):
|
||||||
client, addr = s.accept()
|
print ('Waiting for connections..')
|
||||||
print ('Connected to ' + addr[0] + ':' + str(addr[1]))
|
client, addr = s.accept()
|
||||||
|
print ('Connected to ' + addr[0] + ':' + str(addr[1]))
|
||||||
|
|
||||||
# Read request from client
|
# Read request from client
|
||||||
data = client.recv(1024)
|
data = client.recv(1024)
|
||||||
|
# Should parse client request here
|
||||||
|
|
||||||
# Should parse client request here
|
# Send multipart header
|
||||||
|
client.send("HTTP/1.1 200 OK\r\n" \
|
||||||
|
"Server: OpenMV\r\n" \
|
||||||
|
"Content-Type: multipart/x-mixed-replace;boundary=openmv\r\n" \
|
||||||
|
"Cache-Control: no-cache\r\n" \
|
||||||
|
"Pragma: no-cache\r\n\r\n")
|
||||||
|
|
||||||
# Send multipart header
|
# FPS clock
|
||||||
client.send("HTTP/1.1 200 OK\r\n" \
|
clock = time.clock()
|
||||||
"Server: OpenMV\r\n" \
|
|
||||||
"Content-Type: multipart/x-mixed-replace;boundary=openmv\r\n" \
|
# Start streaming images
|
||||||
"Cache-Control: no-cache\r\n" \
|
# NOTE: Disable IDE preview to increase streaming FPS.
|
||||||
"Pragma: no-cache\r\n\r\n")
|
while (True):
|
||||||
|
clock.tick() # Track elapsed milliseconds between snapshots().
|
||||||
|
frame = sensor.snapshot()
|
||||||
|
cframe = frame.compressed(quality=35)
|
||||||
|
header = "\r\n--openmv\r\n" \
|
||||||
|
"Content-Type: image/jpeg\r\n"\
|
||||||
|
"Content-Length:"+str(cframe.size())+"\r\n\r\n"
|
||||||
|
client.send(header)
|
||||||
|
client.send(cframe)
|
||||||
|
|
||||||
# FPS clock
|
|
||||||
clock = time.clock()
|
|
||||||
# Start streaming images
|
|
||||||
while (True):
|
while (True):
|
||||||
clock.tick() # Track elapsed milliseconds between snapshots().
|
try:
|
||||||
frame = sensor.snapshot()
|
start_streaming(s)
|
||||||
cframe = frame.compressed(quality=90)
|
except OSError as e:
|
||||||
client.send("\r\n--openmv\r\n" \
|
print("socket error: ", e)
|
||||||
"Content-Type: image/jpeg\r\n"\
|
#sys.print_exception(e)
|
||||||
"Content-Length:"+str(cframe.size())+"\r\n\r\n")
|
|
||||||
client.send(cframe)
|
|
||||||
print(clock.fps())
|
|
||||||
client.close()
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user