Ask Your Question

Revision history [back]

Can't play avi video (Anaconda 2)

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.

import cv2 import numpy as np

Create our body classifier

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

Initiate video capture for video file

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

Loop once video is successfully loaded

while cap.isOpened():

# Read first frame
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)
# Pass frame to our body classifier
bodies = body_classifier.detectMultiScale(gray, 1.2, 3)

# Extract bounding boxes for any bodies identified
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()

click to hide/show revision 2
retagged

updated 2017-07-27 20:32:26 -0600

berak gravatar image

Can't play avi video (Anaconda 2)

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.

import cv2 import numpy as np

Create our body classifier

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

Initiate video capture for video file

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

Loop once video is successfully loaded

while cap.isOpened():

# Read first frame
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)
# Pass frame to our body classifier
bodies = body_classifier.detectMultiScale(gray, 1.2, 3)

# Extract bounding boxes for any bodies identified
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()

Can't play avi video (Anaconda 2)

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

Create our body classifier

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

Initiate video capture for video file

cv2.CascadeClassifier('haarcascade_fullbody.xml') cap = cv2.VideoCapture('walking.avi')

Loop once video is successfully loaded

cv2.VideoCapture('walking.avi') while cap.isOpened():

# Read first frame
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)
# Pass frame to our body classifier
 bodies = body_classifier.detectMultiScale(gray, 1.2, 3)

# Extract bounding boxes for any bodies identified
 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()

Can't play avi video (Anaconda 2)

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 True.

import cv2

cap = cv2.VideoCapture(0) cv2.VideoCapture(0)

print(cap.isOpened())

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

import cv2

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

print(cap.isOpened())

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

import cv2 cv2

import numpy as np np

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

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

while cap.isOpened(): 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()

cap.release()

cv2.destroyAllWindows()