Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Count Non Zero error!

Here's a part of my code

# If foreground construct label mask and count the number of pixels
labelMask = np.zeros(thresh.shape, dtype="uint8")
labelMask[labels == label] = 255
numPixels = cv2.countNonZero(labelMask)

I'm getting this error which I'm not able to understand, even after trying to google for the solution

OpenCV Error: Assertion failed (cn == 1) in countNonZero, file /tmp/opencv3-20170817-33981-15wdezm/opencv-3.3.0/modules/core/src/stat.cpp, line 1352
Traceback (most recent call last):
  File "/Users/santhoshdc/23_08_2017/connected_component_Analysis.py", line 28, in <module>
numPixels = cv2.countNonZero(labelMask)
cv2.error: /tmp/opencv3-20170817-33981-15wdezm/opencv-3.3.0/modules/core/src/stat.cpp:1352: error: (-215) cn == 1 in function countNonZero

How do I correct this?

Count Non Zero error!

Here's a part of my code

# If foreground construct label mask and count the number of pixels
labelMask = np.zeros(thresh.shape, dtype="uint8")
labelMask[labels == label] = 255
numPixels = cv2.countNonZero(labelMask)

I'm getting this error which I'm not able to understand, even after trying to google for the solution

OpenCV Error: Assertion failed (cn == 1) in countNonZero, file /tmp/opencv3-20170817-33981-15wdezm/opencv-3.3.0/modules/core/src/stat.cpp, line 1352
Traceback (most recent call last):
  File "/Users/santhoshdc/23_08_2017/connected_component_Analysis.py", line 28, in <module>
numPixels = cv2.countNonZero(labelMask)
cv2.error: /tmp/opencv3-20170817-33981-15wdezm/opencv-3.3.0/modules/core/src/stat.cpp:1352: error: (-215) cn == 1 in function countNonZero

How do I correct this?