Error while counting non-zero pixels

I would like to count a non-zero pixel of an image without converting the image to a Numpy array. Here is the piece of code I have

from PIL import Image, ImageDraw
import cv

image = Image.new('1', (100, 100)) 
draw = ImageDraw.Draw(image)
draw.ellipse((20, 20, 80, 80), fill ='white')
non_zeros = cv.CountNonZero(image)

      

However, when I run this, I get the following error:

TypeError: CvArr argument 'arr' must be IplImage, CvMat or CvMatND. Use fromarray() to convert numpy arrays to CvMat or cvMatND

      

How can I solve this problem? either by continuing with help cv.CountNonZero

, or in any other way that is cheap and effective.

+3


source to share





All Articles