I get an error with the following code:
img = cv2.imread('temp.jpg')
z = cv2.countNonZero(img)
print(z)
OpenCV Error: Assertion failed (cn == 1) in cv::countNonZero, file D:\Build\OpenCV\opencv-3.1.0\modules\core\src\stat.cpp, line 1342
Traceback (most recent call last):
File "C:\Users\hasee\Desktop\open\GuiFeaturesinOpenCV\Performance Measurement and Improvement Techniques\TestTickCount.py", line 29, in <module>
z = cv2.countNonZero(img)
cv2.error: D:\Build\OpenCV\opencv-3.1.0\modules\core\src\stat.cpp:1342: error: (215) cn == 1 in function cv::countNonZero
But, use if I numpy function it is ok:
z = np.count_nonzero(img)
print(z)
I don't understand why.