【问题标题】:How to handle the OpenCV(4.5.3)如何处理 OpenCV(4.5.3)
【发布时间】:2022-01-22 23:27:42
【问题描述】:

我们正在使用支持向量机 (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

【问题讨论】:

  • 停止使用图片欢迎来到Stack Overflow.。为了让我们帮助您,您有必要展示您的努力并提交数据以用于重现您的问题。虽然提供图像很有帮助,但它不允许重现问题。请编辑您的问题以显示最小的可重现集。详情请见Minimal Reproducible Example。
  • 您可以考虑使用pathlib 而不是os。你需要另一个/吗?例如,img = cv2.imread('./data/Training/'+i,0)。

标签: python opencv


【解决方案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

【讨论】:

    猜你喜欢
    • 2021-09-26
    • 2020-06-01
    • 2021-09-27
    • 1970-01-01
    • 2018-11-27
    • 2012-06-07
    • 2011-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多