opencv python中两种二进制图像的比较

2024-10-01 04:59:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要比较两个二进制图像。我目前只计算图像上黑色像素的数量,如果它接近模板值或略高于模板值,则表示它们相似。否则,它们就不一样了

这是我在图像上找到黑色像素数的代码

#Get all non-black pixels 
count = cv2.countNonZero(thresh_temp)
# get pixel count of image
height, width= thresh_temp.shape
cntPixels = height*width
# compute all black pixels
 cntBlack = cntPixels - count
print('This is only black pixels',cntBlack)

Tags: 图像模板count二进制像素allwidthtemp