numpy 计算矩阵中指定元素的个数
import numpy as npimport cv2 as cvimg = np.zeros((200,200)).astype(np.uint8)img[100:200,100:200] = 128img[:100,:100] = 255img[:10,:10] = 9print(np.sum(img==0))cv.imshow('img',img)cv.waitKey()