0
votes

There is not much to work with, that's why the title is so "vague". I first tried to use the cv2, for some task I needed in my work, but it failed on the first try so I ended up testing just the basic code snippet. Which, does not seem to work at all.

import cv2

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

while True:
    # Capture frame-by-frame
    ret, frame = cap.read()

    # Our operations on the frame come here
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    # Display the resulting frame
    cv2.imshow('frame', gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

Frame, is a None value. Code fails. Even the cap object, seems to be nothing basically when I try the PyCharm IDE debug mode, to check its "contents".

What I tried so far

  1. The video is definitely valid an plays normally
  2. Tried inputting the direct path
  3. os.getcwd() gives the same directory as the video is in
  4. Tried different videos of different formats (avi, mp4)
  5. Reinstalled cv2 in various ways several times (slightly disorganized as I frantically tried to fix the problem)
  6. Used a cap.read("file") option to no avail
  7. print(cv2.version) >> 3.3.0

Potential clues

In terms of debugging its a nightmare, because I get zero useful information since the code does not throw an error until it performs an operation on Frame which is None.

PyCharm IDE, says that cv2.VideoCapture has an unexpected argument. More then that, I have no idea what is going on.

I tried many things with the reinstalling, and the versions it seems to return are correct, but I don't know ways of checking if the installation is correct.

Info about my system

I am running an Ubuntu 14.04 (Trusty).

Python3 - other stuff works

PyCharm 2017

If there is more info I should provide, let me know? Also, if you have suggestions how to improve the title, to be more informative let me know.

1
what is the output of opencv_version in terminal?zindarod
It returns 3.3.0.SirSteel
Try cv2.VideoCapture(0) to capture from your webcam. Comment result.zindarod
Did you installed openCV from sources or from a repo? could it be that opencv can not decode such video? have you tried with the webcam (@Zindarod comment) or with another file encoded diffrently, like mpg. Just as a comment, you should check the ret value (which in this case is probably false) before using frame, to avoid a bad capture damage your code.api55
Webcam has the same issue. I tried cv2.VideoCapture(0), and it was the same. I installed OpenCV using this script: raw.githubusercontent.com/jayrambhia/Install-OpenCV/master/…SirSteel

1 Answers

0
votes

Do you have ffmpeg installed? If you don't have ffmpeg, you can't load videos in linux.