Home Cannot open video in python (OpenCV)
Reply: 0

Cannot open video in python (OpenCV)

rocko Published in 2018-01-11 16:45:33Z

I'm new to python and I've just tried to open a video file and... I have no errors, but it doesn't show anything. The video and the programm are in the same folder. I'm using Python 2.7.11 on win32. I've tried the code with a .avi file and a .mp4, but the results were the same... I've also tried to copy opencv_world310.dll from the opencv folder to the python folder, but it still not showing anything. Also, I've tried copying opencv_ffmpeg310.cmake to the python folder, but no luck neither...

Here is the code:

import numpy as np
import cv2

cap = cv2.VideoCapture('VID_20170727_175524.mp4') #Open video file

    ret, frame = cap.read() #read a frame
        frame2 = frame
        #if there are no more frames to show...

    line1 = np.array([[100,100],[300,100],[350,200]], np.int32).reshape((-1,1,2))
    line2 = np.array([[400,50],[450,300]], np.int32).reshape((-1,1,2))

    frame2 = cv2.polylines(frame2,[line1],False,(255,0,0),thickness=2)
    frame2 = cv2.polylines(frame2,[line2],False,(0,0,255),thickness=1)

    cv2.imshow('Frame 2',frame2)

    #Abort and exit with 'Q' or ESC
    k = cv2.waitKey(30) & 0xff
    if k == 27:

cap.release() #release video file
cv2.destroyAllWindows() #close all openCV windows
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.33161 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO