OpenCV real time streaming video capture is slow. How to get synced with real time?

25 views Asked by At

I'm using Python OpenCV to receive rtsp images in real time.

But there's a problem with the video being shown being too late and cutting off.

I'm looking for a way to sync in real time..

(For your information, even if there is no recognized part of the object below, it appears at the same speed...)

  • cv2 speed

enter image description here

class Camera:
    def __init__(self, source, PT_PATH):
        self.capture = cv2.VideoCapture(source)
        if not PT_PATH == "original":
            self.model = load_model(PT_PATH)
        else:
            self.model = "original"
        self.streaming_state = False

    def start(self):
        self.streaming_state = True

    def stop(self):
        self.streaming_state = False
        self.capture.release()
        print("memory check : ",self.capture.isOpened())


    def read_frames(self):
        while self.streaming_state:
            # print("capture 상태 : ",self.capture.isOpened())
            success, capture_img = self.capture.read()
            if not success:
                print("not read frame")
                break
            
            if not self.model == "original":
                pre_process_image, model_to_device = preprocess_frame(capture_img=capture_img, model=self.model)
                post_process_image = postprocess_frame(pre_process_image, capture_img, model_to_device)
                yield (b'--frame\r\n'
                        b'Content-Type: image/jpeg\r\n\r\n' + post_process_image + b'\r\n')
            else:
                capture_img = httpProcessing(capture_img=capture_img)
                yield (b'--frame\r\n'
                        b'Content-Type: image/jpeg\r\n\r\n' + capture_img + b'\r\n')

Questions:

What am I doing wrong here?

Why is it so slow?

How do I sync it to real-time speeds?

0

There are 0 answers