OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

Viewed 30

I am getting this error. I think there is a problem with the function.

import cv2
import os
import matplotlib.pyplot as plt
import numpy as np

img_array = cv2.imread("Dataset/Face_Mask/00000/00000_Mask.jpg")

plt.imshow(img_array)

plt.imshow(cv2.cvtColor(img_array, cv2.COLOR_BGR2RGB))

img_array.shape

Datadirectory = "Dataset/" #Training dataset
Classes = ["Face_Mask","No_Mask"] #List of classes
for category in Classes:
    path = os.path.join(Datadirectory, category) #// it will join the path
    for img in os.listdir(path):
        img_array = cv2.imread(os.path.join(path,img))
        #back2rgb
        plt.imshow(cv2.cvtColor(img_array, cv2.COLOR_BGR2RGB))
        plt.show()
        break
    break
0 Answers
Related