0
import cv2
import numpy

cap = cv2.VideoCapture("test1.avi")  

while 1:
    ret, frame = cap.read()
    cv2.imshow("cap", frame)
    if cv2.waitKey(100) & 0xff == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()

my code explain in above and its working perfectly in windows.but when in ubuntu 16.04 it gives an error. please explain the solution

Unable to stop the stream: Inappropriate ioctl for device
OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /home/travis/miniconda/conda-bld/conda_1485299288502/work/opencv-3.2.0/modules/highgui/src/window.cpp, line 304
Traceback (most recent call last):
  File "opncv_ex4.py", line 7, in <module>
    cv2.imshow("cap", frame)
cv2.error: /home/travis/miniconda/conda-bld/conda_1485299288502/work/opencv-3.2.0/modules/highgui/src/window.cpp:304: error: (-215) size.width>0 && size.height>0 in function imshow

Ubuntu 16.04 and opencv 3.2 python 2.7

Lanka
  • 103
  • 1
  • 1
  • 2

1 Answers1

0
  1. The code waits too long to stop with if cv2.waitKey(100) & 0xff == ord('q'): so change the 100 to 10 as follows: if cv2.waitKey(10) & 0xff == ord('q'): After changing this line of code, your Python script will work perfectly in the terminal.

  2. This link lists to a webpage with very short sample .avi videos that are perfect for testing your code. If you are running the script from the terminal the .avi video must be located in the current directory.

  3. If steps 1 and 2 didn't work, as usual Anaconda is the culprit. Anaconda is basically a Windows/Mac program that is completely duplicated by packages in the default Ubuntu repositories except that Anaconda has problem finding any Python modules which weren't installed by Anaconda unless special configuration is done to tell Anaconda where the missing Python modules are located. Or you can give up and install OpenCV from the default Ubuntu repositories and stop messing with Anaconda.

    sudo apt install python-opencv 
    
karel
  • 114,770