Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

In Python, is there a method or operator to determin is a frame is empty or an all zero-matrix?

For example, I would like to finish this code:

import cv2
import numpy as np

cap = cv2.VideoCapture(0)

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

    if # frame is empty or all zeros #:
        print("Empty Frame")
    else:
        cv2.imshow('frame',frame)

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

cv2.destroyAllWindows()

The line, 'if # frame is empty or all zeros #:', is there an operator I can use to determine if a frame is empty?

In Python, is there a method or operator to determin is a frame is empty or an all zero-matrix?

For example, I would like to finish this code:

import cv2
import numpy as np

cap = cv2.VideoCapture(0)

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

    if # frame is empty or all zeros #:
        print("Empty Frame")
    else:
        cv2.imshow('frame',frame)

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

cv2.destroyAllWindows()

The line, 'if # frame is empty or all zeros #:', is there an operator I can use to determine if a frame is empty?