Live Stream text to html tamplets from Django

i have a function at the backend in django that calculate and return frames speed of a video given to OpenCv.videoCapture() .the type of the speed is float .

class video_feed(object):
    def __init__(self, pathVideo):    
    self.cap = cv.VideoCapture(pathVideo) 
    #some code .....       
    
    def __del__(self):
        self.cap.release()

    def get_frames(self):
    #some code ...    
    return speed_list

this method keep calling the method while the video is working :

def gen_speed(video_feed):
    print('this is spped generation method')
    while True:
        speed = video_feed.get_frames()        
        yield(speed)
@gzip.gzip_page
def speed_frame(request):
    try:
        pathVideo = "video_detection/statics/rl4_pb8-7.mp4"
        cam = model.video_feed(pathVideo)
        #return StreamingHttpResponse(model.gen_test(cam),content_type="text/csv")
        return HttpResponse({'speed':cam.get_frames()})
    except:
        print("speed_frame not working !!!!!!!!!!!!!!!!!!!!!!!!")

but this code doesn't work . i need a way to make the speed stream to my html page so i can use it in a chartjs.

streaming video using openCv is woking just fine but when i change the type to float it doesn't work .

I finally found a better way. Which is using Django channels to stream data in JSON format.

Back to Top