IP Camera OpenCV Image Overread

asked 2019-10-09 03:13:53 -0500

I have difficulties to process IP Camera images on my RPI 4 (even on my Mac) with OpenCV and Python. My project is to acquire IP Camera images (RGB - 1920 x 1080) and process them with object detection algorithm. I don’t have any real time constraint. If I could run the algorithm about every 5 min, it would be perfect.

OpenCV version: 4.1.1 Python version : 3.6.5

I simplified my code to:

import cv2, time
cap = cv2.VideoCapture(‘URL’)
if (cap.isOpened()== False):
        print("Error opening video stream or file")

sampleTime = 10 # in seconds
imgCounter = 0
startTime = time.time()

while True:
        ret, frameCaptured = cap.read()

        if time.time() - startTime >= sampleTime and ret == True:
                startTime = time.time()

                # Do some stuff here
                time.sleep(5)
                cv2.imshow('Captured Image', frameCaptured)
                imgCounter += 1
                print("Image:",imgCounter)

        if cv2.waitKey(1) & 0xFF == ord('q'):
                break

cap.release()
cv2.destroyAllWindows()

Finally, the first image is acquired and then the variable ret becomes False. Without the condition “ret == True”, I see a green area appearing on the second image and then the execution stops. Image: 1 [mjpeg @ 0x7ff6ac808000] overread 8

edit retag flag offensive close merge delete