Re: Streaming images with HttpResponse?
yield "<html>"
yield '<meta http-equiv="refresh" content="0.01" />'
yield "<body>\n"
rval, frame = settings.CAP.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imwrite('media/image.jpeg', gray, [int(cv2.IMWRITE_JPEG_QUALITY), 90])
x={"src": "..%s/image.jpeg" % (settings.MEDIA_URL), "alt": "Video Frame"}
yield '<img src="%(src)s" alt="%(alt)s"/>' % x
yield "</body></html>\n"
However as it doesn't stream the images but instead it saves and the html is refreshed every 0.01 secs. This does not seem to be an elegant solution because a) there is latency and b) the browser keeps reloading constantly. Some of you suggested websockets. Is there some good example for Django + Websockets for streaming images to the browser?
On Friday, November 15, 2013 11:15:21 AM UTC-5, Alex Karargyris wrote:
I have this simple app that I opens webcam and processes the frames using OpenCV. In my views.py I have the following code:def processImage():while True:rval, frame = settings.CAP.read() //Read frames from webcamgray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) //Make frame grayscalepil_img = Image.fromarray(gray)response = HttpResponse(mimetype="image/png") pil_img.save(response, "PNG")return responseAlthough there is a while loop the function runs only once because it is broken by "return response". How could I change the code to make it run constantly?
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/60f5ed0b-2179-4c63-9d9b-159ff8381049%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home