Ask Your Question
0

Can't play avi video (Anaconda 2)

asked 2017-07-27 20:22:09 -0600

DavidStark gravatar image

updated 2017-07-27 22:46:38 -0600

The code was able to execute. However, it wouldn't play the video. I copied opencv_ffmpeg.dll to C:\Anaconda2\ and saved it as opencv_ffmpeg2411_64.dll. It didn't resolve my problem.

The code below returns True.

import cv2

cap = cv2.VideoCapture(0)

print(cap.isOpened())

However, when I changed to a file name from 0. It will return False.

import cv2

cap = cv2.VideoCapture('walking.avi')

print(cap.isOpened())

Here is the code that will play 'walking.avi'.

import cv2

import numpy as np

body_classifier = cv2.CascadeClassifier('haarcascade_fullbody.xml')

cap = cv2.VideoCapture('walking.avi')

while cap.isOpened():

ret, frame = cap.read()

frame = cv2.resize(frame, None,fx=0.5, fy=0.5, interpolation = cv2.INTER_LINEAR)

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

bodies = body_classifier.detectMultiScale(gray, 1.2, 3)

for (x,y,w,h) in bodies:

    cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 255), 2)

    cv2.imshow('Pedestrians', frame)

if cv2.waitKey(1) == 13: #13 is the Enter Key

    break

cap.release()

cv2.destroyAllWindows()

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-07-28 08:04:51 -0600

berak gravatar image

yes, you need the opencv_ffmpeg.dll (whatever the correct name is for your os/opencv version) on the PATH or next to your python script. the anaconda root folder might be the wrong place, and any renaming of the dll will be a bad idea.

edit flag offensive delete link more

Comments

My anaconda root folder is in C:\Users\David\Anaconda2. Sorry about the typo.

DavidStark gravatar imageDavidStark ( 2017-07-28 13:30:28 -0600 )edit

still, not a valid placefor the dll. instead, add the folder, where that dll is now , to the global PATH environment.

berak gravatar imageberak ( 2017-07-28 13:44:54 -0600 )edit

I added the folder to the global path environment. I couldn't play the video.

DavidStark gravatar imageDavidStark ( 2017-07-28 15:03:41 -0600 )edit

I installed OpenCV thorugh the terminal conda install -c menpo opencv. Maybe this is the cause?

DavidStark gravatar imageDavidStark ( 2017-07-28 18:33:46 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-07-27 20:22:09 -0600

Seen: 608 times

Last updated: Jul 28 '17