Friday, November 15, 2013

Re: Streaming images with HttpResponse?

I Alex.

I believe that is not possible with Django views. Views are made for request-response, i.e. the client sends a request, the view returns a response, and that's it, end of connection.

In your case, the server has a stream of data that you want to constantly send to the client. This sounds like a standard problem for using Websockets.

Within Django, there are some apps for using Websockets, even though I don't know how websockets work well for video.

Hope this helps,
Jorge




On Fri, Nov 15, 2013 at 5:15 PM, Alex Karargyris <akarargyris@gmail.com> 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 webcam
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)         //Make frame grayscale
        pil_img = Image.fromarray(gray)  
        
        response = HttpResponse(mimetype="image/png")
        pil_img.save(response, "PNG")
        
        return response

Although 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/a13fe785-83ec-4a18-8377-090bdeda279d%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
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/CAOYPqDAB1HiW9PLVngYeUxqOF365-QE5bEe9yjLF2xJkp_7X6w%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment