Home > Blockchain >  How to handle the OpenCV(4.5.3)
How to handle the OpenCV(4.5.3)

Time:12-26

We are implementing the code for brain tumor classification using Support Vector Machine (SVM). But the error arises by running the final block of code.

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

enter image description here

CodePudding user response:

The problem is with the os.listdir ./data/Training/ where I consider retrieving all of the data from the dataset and trying to display with tumor exist and the tumor does not exist. Which is not possible. So for solving the problem, I used the following os.listdir./data/Training/no_tumor/ and now it will give me a result, by determining which image contains the tumor and which one does not.

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

```[![Here is the output of the given code][1]][1]

  [1]: https://i.stack.imgur.com/ql2qX.png
  • Related