I am trying to capture a video and convert into frames using python and openCV. I followed the steps that need to done to import openCV2 libraries for python in windows 8 which is as follows:
Download Python, Numpy, OpenCV from their official sites.
Extract OpenCV (will be extracted to a folder opencv)
Copy ..\opencv\build\python\x86\2.7\cv2.pyd
Paste it in C:\Python27\Lib\site-packages
Open Python IDLE or terminal, and type
I have done the above steps to import opencv libraries into python.
But when I import CV2 libraries and try to capture a video, I was unable to generate frames using the function cv.CaptureFromFile()
and accessing the frames using cv.QueryFrame()
functions. I was unable to capture the frames. Please find the code below.
import sys
import os
import numpy as np
import PIL
from matplotlib import pyplot as plt
import cv2.cv as cv
winname = "myWindow"
win = cv.NamedWindow(winname, cv.CV_WINDOW_AUTOSIZE)
invideo = cv.CaptureFromFile("chayya1.avi")
totalNumberOfFrames = int(cv.GetCaptureProperty(invideo, cv.CV_CAP_PROP_FRAME_COUNT))
framesprocessing = totalNumberOfFrames
print(totalNumberOfFrames)
while (True):
im = cv.QueryFrame(invideo)
cv.ShowImage(winname, im)
if cv.WaitKey() == 27: # ASCII 27 is the ESC key
break
del invideo
cv.DestroyWindow(winname)
The output is getting processed without any errors but the frames are not generating and even the print statement for frame count is also zero.
I just want to what is procedure for installing OpenCV for python in windows and accessing the frames of a video using the obove mentioned functions.
Thanks in advance