Opencv python does not open any video file [closed]

asked 2017-03-22 05:03:49 -0600

I have open cv 3.2.0 in python 2.7.13 on windows 10. Eventually I would like to run a background substractor, but I`m stuck in the very first step. I am not being able to make make to show a frame from a video in a file. Here is the code I have tried to far

import cv2
cam = cv2.VideoCapture("C:\\Users\\Public\\Videos\\Sample Videos\\wildlife.avi")
worked,f = cam.read()
cv2.imshow('f',f)
k=cv2.waitKey(1)

cv2.imshow() gives the following error:

  "error: (-215) size.width>0 && size.height>0 in function cv::imshow"

worked is always returning FALSE, which according to what I could google it implies cam.read() is not reading the frame correctly

I google for solutions but so far none worked. Tried to use , different movies, formats (mp4,avi,wmv), internal codecs (h264, msmpeg4v2). I saw some suggestion of recompiling the library to better interact with 3rd party codecs, but I got opencv from the website, and numpy and matplotlib through pip. It seems drastic to redo it.

Does anyone knows what might be going on?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by berak
close date 2017-03-22 05:36:38.568047

Comments

1
  • make sure, opencv_ffmpeg(_64).dll is on the PATH (or next to your app)
  • check cam.isOpened() and worked before going on
berak gravatar imageberak ( 2017-03-22 05:17:15 -0600 )edit

First guess, this is due to your windows backend not supporting your codec of the video you are trying to read. I just tried it on Ubuntu with a random *.mp4 video and it works out of the box.

StevenPuttemans gravatar imageStevenPuttemans ( 2017-03-22 05:17:31 -0600 )edit
2

Thank you, once i put opencv_ffmpeg(_64).dll it worked. Wish I could upvote but I do not have enough points

naturian gravatar imagenaturian ( 2017-03-22 05:27:18 -0600 )edit
1

your "thank you" is entirely enough ;)

berak gravatar imageberak ( 2017-03-22 05:36:00 -0600 )edit