I'm trying to calculate the number of non-zero brightness pixels in a gray image.
When I used cv2.countNonZero, TypeError: Expected Ptr
I got this error and want to resolve this error.
Corresponding source code
---->8 cnt = cv2.countNonZero (thresh) TypeError: Expected Ptr<cv :: UMat>for argument'% s'
What I tried
import cv2 import numpy as np img = cv2.imread ('/content/Blue.jpg') # Count the number of pixels with 1 pixel. thresh = cv2.threshold (img, 1,255, cv2.THRESH_BINARY) cnt = cv2.countNonZero (thresh) print (cnt)
I performed mask processing and used the image (/content/Blue.jpg) divided into R, G, B, so I checked if I used a library such as pil in the previous processing. ..Supplementary information (FW/tool version, etc.)
It may be a naive question, but thank you ...
Blue.jpg is the following image.
Answer # 1
By not using cv2.countNonZero, I was able to calculate the number of pixels with non-zero brightness.
It's not the ultimate solution to my question, but I was able to achieve my goal.
import cv2 import numpy as np img = cv2.imread ('/content/Blue.jpg') # Count the number of pixels whose brightness is 1 or more. n_pixels = (0
- python - typeerror: expected ptr for argument cause and solution of'% s'
- python - typeerror: first argument must be string or compiled pattern error occurs and html is not displayed and i am in trouble
- python importerror i want to resolve
- python - mysterious argument () error when using optuna + lihgtgbm i want to somehow store the best parameters
- python - i want to pass a list as an argument of glob and repeat it
- python - valueerror: field'id' expected a number but got'suzukitadashi'
- python - typeerror: can't multiply sequence by non-int of type'list'
- python - about typeerror
- python - i want to solve the problem that i get the error typeerror: xxxxxxxx takes no arguments
- python - tuple error does not resolve
- python: what does it mean to give an argument to super ()?
- python - when i set the uuid field in django, i get field'object_id' expected a number but got '78a0767cb607488087a73f17565bb
- python - error when using bamcoverage: how to resolve segmentation fault
- python - the argument is referenced only once
- python - i get an argument must be int or float error in django
- python - i want to resolve the error message
- python - i don't know how to resolve this error in sqlalchemy
- python - twitterapi i want to resolve errors when acquiring follower information
- python - idle cannot resolve the "rootgeometry" error