如何处理 OpenCV(4.5.3)

How to handle the OpenCV(4.5.3)

我们正在使用支持向量机 (SVM) 实现脑肿瘤分类代码。但是错误是由 运行 最后的代码块引起的。

plt.figure(figsize=(12,8))
c=1
for i in os.listdir('./data/Training'):
    plt.subplot(4,4,c)
    img  = cv2.imread('./data/Training'+i,0)
    img1 = cv2.resize(img, (200,200))
    img1 = img1.reshape(1 ,-1)/255
    p = sv.predict(img)
    plt.title(dec[p[0]])
    plt.imshow(img, cmap="gray")
    plt.axis('off')
    c+=1

问题出在 os.listdir ./data/Training/ 中,我考虑从数据集中检索所有数据并尝试显示肿瘤存在和肿瘤不存在。这是不可能的。所以为了解决这个问题,我使用了下面的 os.listdir./data/Training/no_tumor/ 现在它会通过确定哪个图像包含肿瘤而哪个不包含肿瘤来给我一个结果。

plt.figure(figsize=(12,8))
p = os.listdir('./data/Training/')

c=1
for i in os.listdir('./data/Training/no_tumor/')[:16]:
    plt.subplot(4,4,c)
    img  = cv2.imread('./data/Training/no_tumor/'+i,0)
    img1 = cv2.resize(img, (200,200))
    img1 = img1.reshape(1 ,-1)/255
    p = sv.predict(img1)

    plt.title(dec['no_tumor'])
    plt.imshow(img, cmap="gray")
    plt.axis('off')
    c+=1