In Python, is there a method or operator to determine if 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?
a frame with all pixels set to 0 is not an empty frame : it's a black image. You can use countNonZero function.
read doc is here