Ask Your Question
0

Can't Play video from file

asked 2018-05-11 13:09:13 -0500

I'm using playingvideofromfile line for line, but using the full path of the file.

still get the following error: OpenCV(3.4.1) C:\bld\opencv_1520732670222\work\opencv-3.4.1\modules\imgproc\src\color.cpp:11147: error: (-215) scn == 3 || scn == 4 in function cv::cvtColor

edit retag flag offensive close merge delete

Comments

can you replace capr.read() with

ret, frame = cap.read()
# Our operations on the frame come here
if ret==True:
    gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
else:
    print ('cannot read frame')
LBerger gravatar imageLBerger ( 2018-05-11 13:21:03 -0500 )edit

Same error, it keeps pointing to gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

MarcinRosol gravatar imageMarcinRosol ( 2018-05-11 13:35:45 -0500 )edit

add print (frame.shape) after cap.read()

LBerger gravatar imageLBerger ( 2018-05-11 13:48:13 -0500 )edit

python users NEVER do checks, like `cap.isOpened() or ret==True

when playing a video file , the last frame will return False there.

berak gravatar imageberak ( 2018-05-11 13:58:58 -0500 )edit
1

this worked adding these conditions. I guess the program didn't know what to do when the video finished.

MarcinRosol gravatar imageMarcinRosol ( 2018-05-14 14:14:49 -0500 )edit

the program is dumb.

the programmer did not know, what to do ;)

berak gravatar imageberak ( 2018-05-14 14:23:35 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-05-11 14:12:29 -0500

LBerger gravatar image

updated 2018-05-11 14:33:18 -0500

berak gravatar image

but @MarcinRosol said that source code is https://docs.opencv.org/3.0-beta/doc/... (Play video from file ) and it is checked in this source code. @MarcinRosol did you copy exactly source code?

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

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

    if ret==False:
          print ('cannot read frame')
          break

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

cap.release()
cv2.destroyAllWindows()
edit flag offensive delete link more

Comments

This worked. Thanks! Just trying to figure out why now.

MarcinRosol gravatar imageMarcinRosol ( 2018-05-14 13:50:52 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2018-05-11 13:09:13 -0500

Seen: 1,055 times

Last updated: May 11 '18