我不知道如何修复这个错误 - AttributeError: 'str' object has no attribute 'decode'

问题描述 投票:0回答:0

将 numpy 导入为 np 导入cv2 从 tensorflow.keras.models 导入 load_model

框架宽度= 640
框架高度 = 480 亮度 = 180 阈值 = 0.75
字体 = cv2.FONT_HERSHEY_SIMPLEX

cap = cv2.VideoCapture(0) cap.set(3, frameWidth) cap.set(4, frameHeight) cap.set(10, 亮度)

model = load_model("my_model_new.h5")

def 灰度(img): img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) 返回 img

def 均衡(img): img =cv2.equalizeHist(img) 返回 img

def 预处理(img): img = 灰度(img) img = 均衡(img) 图片=图片/255 返回 img

def getClassName(classNo): 如果 classNo == 0: 返回 'Speed Limit 20 km/h' elif classNo == 1: return 'Speed Limit 30 km/h' elif classNo == 2: return 'Speed Limit 50 km/h' elif classNo == 3: return 'Speed Limit 60 km/h' elif classNo == 4: return 'Speed Limit 70 km/h'

虽然正确:

成功,imgOriginal = cap.read() img = np.asarray(imgOriginal) img = cv2.resize(img, (32, 32)) img = 预处理(img) cv2.imshow("处理后的图像", img) img = img.reshape(1、32、32、1)

predictions = model.predict(img) classIndex = np.argmax(预测)

predictions = model.predict(img) probVal = np.amax(预测) 如果 probVal > 阈值:

cv2.putText(imgOriginal, str(getClassName(classIndex))+" "+ str(probVal),(50,50),font,1,(0,0,255),1,cv2.LINE_AA) cv2.imshow("原始图像", imgOriginal)

如果 cv2.waitKey(1) 和 0xFF == ord('q'): 休息

这是代码,请告诉我这个错误的修复方法

python-3.x opencv attributeerror
© www.soinside.com 2019 - 2024. All rights reserved.