OpenCV Error: (-215)size.width>0 && size.height>0 in function imshow

前端 未结 16 2328
既然无缘
既然无缘 2020-11-29 09:09

I am trying to make a face tracker that combines Haar Cascade Classification with Lucas Kanade good feature detection. However, I keep getting an error that I cannot figure

相关标签:
16条回答
  • 2020-11-29 09:35
    while(cap.isOpened()):
    
        ret, img = cap.read()
        print img
        if img==None:   #termino los frames?
            break   #si, entonces terminar programa
        #gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        cv2.imshow('img2',img)
    
    0 讨论(0)
  • 2020-11-29 09:37

    That error also shows when the video has played fine and the script will finish but that error always throws because the imshow() will get empty frames after all frames have been consumed.

    That is especially the case if you are playing a short (few sec) video file and you don't notice that the video actually played on the background (behind your code editor) and after that the script ends with that error.

    0 讨论(0)
  • 2020-11-29 09:38

    I have also met this issue. In my case, the image path is wrong, so the img read is NoneType. After I correct the image path, I can show it without any issue.

    0 讨论(0)
  • 2020-11-29 09:38

    Although this is an old thread, I got this error as well and the solution that worked for me is not mentioned here.

    Simply put, in my case the webcam was still in use on the background, as I saw the LED light being on. I have not yet been able to reproduce the issue, so I'm not sure a simple cv2.VideoCapture(0).release() would have solved it. I'll edit this post if and when I have found it out.

    For me a restart of my PC solved the issue, without changing anything to the code.

    0 讨论(0)
  • 2020-11-29 09:40

    In these two lines:

    mask = cv2.line(mask, (a,b),(c,d), color[i].tolist(), 2)
    
    frame = cv2.circle(frame,(a, b),5,color[i].tolist(),-1)
    

    try instead:

    cv2.line(mask, (a,b),(c,d), color[i].tolist(), 2)
    
    cv2.circle(frame,(a, b),5,color[i].tolist(),-1)
    

    I had the same problem and the variables were being returned empty

    0 讨论(0)
  • 2020-11-29 09:42

    cv2.circle and cv2.lines are not working. Mask and frame both are returning None. these functions (line and circle) are in opencv 3 but not in older versions.

    0 讨论(0)
提交回复
热议问题