Live Stream text to HTML tamplets

123 views Asked by At

I have a function at the back-end 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.

1

There are 1 answers

0
Aizen-ofc On

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