How to refresh an image with CGI ?
Posted: Wed Oct 01, 2014 9:58 pm
Hello,
I try to realise a web server where a captured picture is visible with a refresh every 1 second.
Only python is used (with Picamera library) . And Apache2 is used as http server.
2 days ago I tried to use a loop to refresh the image, but I learned that the page is sent when all the script is read (Means only at the end of the loop).
Today I don't know how it is possible to refresh the image periodically every second.
Each time I press the refresh button of the browser I use (chrome, Mozilla), I have a new image which comes from a new capture. (manual refresh of the all page)
Here is the index page:
And here is the aide4.py page where the lecture function is coded:
How is it possible to refresh automatically this image ?
Thank you for your help.
I try to realise a web server where a captured picture is visible with a refresh every 1 second.
Only python is used (with Picamera library) . And Apache2 is used as http server.
2 days ago I tried to use a loop to refresh the image, but I learned that the page is sent when all the script is read (Means only at the end of the loop).
Today I don't know how it is possible to refresh the image periodically every second.
Each time I press the refresh button of the browser I use (chrome, Mozilla), I have a new image which comes from a new capture. (manual refresh of the all page)
Here is the index page:
Code: Select all
#!/usr/bin/env python
import cgi
import cgitb
cgitb.enable()
import sys
import time
import io
import aide4
sys.stdout.write("Content-type: image/jpeg\n\n")
aide4.lecture()Code: Select all
#!/usr/bin/env python
import cgi
import cgitb
cgitb.enable()
import sys
import time
import io
import picamera
def lecture():
my_stream=io.BytesIO()
camera=picamera.PiCamera()
camera.resolution=(1296, 972)
camera.capture(my_stream, format='jpeg')
my_stream.seek(0)
sys.stdout.write(my_stream.read())
sys.stdout.flush()
camera.close()Thank you for your help.