opencv python\opencv\modules\imgproc\src\color.cpp:182:错误:(-215:断言失败)_函数';cv::CVT颜色';,,只有凸轮灯打开

opencv python\opencv\modules\imgproc\src\color.cpp:182:错误:(-215:断言失败)_函数';cv::CVT颜色';,,只有凸轮灯打开,python,numpy,opencv3.0,face-recognition,Python,Numpy,Opencv3.0,Face Recognition,我在运行代码时出现以下错误。两个erorr都在运行时显示 Exception in Tkinter callback Traceback (most recent call last): File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python35\lib\idlelib\run.py", line 119, in main seq, request = rpc.request_queue.g

我在运行代码时出现以下错误。两个erorr都在运行时显示

    Exception in Tkinter callback
    Traceback (most recent call last):
      File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python35\lib\idlelib\run.py", line 119, in main
        seq, request = rpc.request_queue.get(block=True, timeout=0.05)
      File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python35\lib\queue.py", line 172, in get
        raise Empty
    queue.Empty

    Traceback (most recent call last):
      File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python35\lib\tkinter\__init__.py", line 1550, in __call__
        return self.func(*args)
      File "C:\Users\Lenovo\Desktop\Face recognise attandace system Succes.py", line 89, in TakeImages
        gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor
这是我的密码。当我运行这个时,我得到了我上面提到的许多错误。当我试图处理主异常时,会发生另一个异常。我还提到了它们的堆栈跟踪

def TakeImages():         
    Id =(txt.get())  
    name =(txt2.get()) 
    if(is_number(Id) and name.isalpha()):
        cam = cv2.VideoCapture(1)
        harcascadePath ="haarcascade_frontalface_default.xml"
        detector = cv2.CascadeClassifier(harcascadePath)  
        sampleNum = 0 
        while(True):
            ret,img = cam.read()
            gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)  
            faces = detector.detectMultiScale(gray, 1.3,5) 
            for (x, y, w, h) in faces:
                cv2.rectangle(img, (x, y), ( x + w, y + h), (255, 0, 0), 2)
                sampleNum=sampleNum + 1
                cv2.imwrite("TrainingImages"+name +"."+Id +'.'+ str(sampleNum) + ".jpg", gray[y:y + h, x:x + w]) 
                cv2.imshow('frame', img) 
            if cv2.waitKey(100) & 0xFF == ord('q'):
                            break
            elif sampleNum>60:
               break
        cam.release() 
        cv2.destroyAllWindows()
        res = "Images Saved for ID: " + Id +" Name: "+ name   
        row = [Id, name]  
        with open('studentDetails\StudentDetails.csv','a+') as csvFile:
            writer = csv.writer(csvFile) 
            writer.writerow(row)
        csvFile.close() 
        message.configure(text = res)
    else:
        if(is_number(Id)):
                res = "Enter Alphabetical Name"
                message.configure(text = res) 
        if(name.isalpha()): 
                res = "Enter Numeric Id"
                message.configure(text = res)