import numpy as np
import cv2
# Open image and make into numpy array
im=cv2.imread("D:/输出试验/模型3/1.jpg")
# Work out what we are looking for
sought = [254,254,254]
# Find all pixels where the 3 RGB values match "sought", and count
result = np.count_nonzero(np.all(im==sought,axis=2))
dpi = 72 #分辨率(像素/英寸)
area = result / (72 * 72) #单位 英寸
print(area)
报错
axis 3 is out of bounds for array of dimension 0
是图片的问题,转换后数组的维度不够。参考:https://blog.csdn.net/lingchuxiao/article/details/107773663
您好,我是有问必答小助手,你的问题已经有小伙伴为您解答了问题,您看下是否解决了您的问题,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632