OpenCV Assertion Fail

Hi all,
We’re running a Jetson Nano with a USB camera for inference purposes… Our system ran for a few weeks and more recently we are getting the following assretion from OpenCV (about once every 100-200 captures):

OpenCV Error: Assertion failed (total() == 0 || data != NULL) in Mat, file /build/opencv-XDqSFW/opencv-3.2.0+dfsg/modules/core/include/opencv2/core/mat.inl.hpp, line 431

The system is Ubuntu 18.04, OpenCV 3.2.0, Python 3. The code snippet calling OpenCV is:

        cam = cv2.VideoCapture(0)
        cam.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('U', 'Y', 'V', 'Y'))
        cam.set(cv2.CAP_PROP_FRAME_WIDTH, 2592)
        cam.set(cv2.CAP_PROP_FRAME_HEIGHT, 1944)
        image_path = None
        if cam.isOpened():
            image_filename = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S") + ".jpg"
            image_path = '{}/{}'.format(OLYNS_PICTURES_PATH, image_filename)
            _, frame = cam.read()
            if crop:
                frame = self.cropped_picture(frame)
            cv2.imwrite(filename=image_path, img=frame)
            cam.release()

Any thoughts? Smells like a memory issue - SD card corruption?

Hi,
Usually we run a gstreamer pipeline in cv2.VideoCapture(). Please refer to the sample:
How to Filesink and Appsink simultaneously in OpenCV Gstreamer. (Gstreamer pipeline included) - #7 by DaneLLL
And give it a try.