Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Python & Video - freeze

Dears,

I got running exampe

import numpy as np
import cv2

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

while(cap.isOpened()):
    ret, frame = cap.read()

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

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

cap.release()
cv2.destroyAllWindows()

When video finishes I got error at Python console and freeze

Traceback (most recent call last):

  File "<ipython-input-1-2cc765029316>", line 1, in <module>
    runfile('C:/tmp/untitled1.py', wdir='C:/tmp')

  File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 685, in runfile
    execfile(filename, namespace)

  File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 71, in execfile
    exec(compile(scripttext, filename, 'exec'), glob, loc)

  File "C:/tmp/untitled1.py", line 16, in <module>
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

error: ..\..\..\modules\imgproc\src\color.cpp:3739: error: (-215) scn == 3 || scn == 4 in function cv::cvtColor

What correctly to stop video?

Best regards, Peter