Ask Your Question
0

Mac with anaconda installed can't play videos

asked 2017-07-29 01:32:55 -0600

I installed openCV 3.1.0 and anaconda 3. I was able to open images. However, when I tried to play this avi file, an error was displayed on the console. error: /Users/travis/miniconda3/conda-bld/opencv_1489542914304/work/opencv-3.1.0/modules/imgproc/src/imgwarp.cpp:3229: error: (-215) ssize.area() > 0 in function resize. Moreover, cap.isOpen() returned True.

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()

File "<ipython-input-1-f44aabb31ae2>", line 18, in <module> frame = cv2.resize(frame, None,fx=0.5, fy=0.5, interpolation = cv2.INTER_LINEAR)

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-07-29 03:00:20 -0600

berak gravatar image

updated 2017-07-29 04:28:57 -0600

you must check the ret value from cap.read().

every movie has an end, when it gets to the last frame, it will return empty (None) frames, then you'll have to break out of the loop, like:

while cap.isOpened():
    ret, frame = cap.read()
    if not ret:
         break
edit flag offensive delete link more

Comments

The value of ret is False. How should I change my code?

openCVStudent gravatar imageopenCVStudent ( 2017-07-29 04:14:53 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-07-29 01:32:55 -0600

Seen: 242 times

Last updated: Jul 29 '17