Friday, November 15, 2013

Streaming images with HttpResponse?

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.

No comments:

Post a Comment